U4-6642 - Sort order messing up after deleting a node

Created by Damiaan Peeters 20 May 2015, 11:03:59 Updated by Stephan 16 Jun 2015, 16:27:32

We see sometimes unpredictable order from IPublishedContent nodes. They tend to switch magically. Also, new nodes are not added at the end of the children.

The reason why new nodes are not attached as the end of the list has to do with the "sortOrder" containing duplicate (or missing) items. The way to solve this is to "Sort" the items manually. After this action the new nodes will be created at the end of the list again and magical switching of nodes on the frond-end will stop.

To reproduce this issue, start a clean Umbraco. Create a home node with 3 childnodes. Delete the second child node. And add a new child node. The sortOrder will contain now 0,2,2.

Concerning the expected result, I expected it to be 0,2,3 or 0,1,2. Not containing duplicate sortOrder values.


Damiaan Peeters 11 Jun 2015, 13:40:40


Stephan 11 Jun 2015, 13:54:39

ContentRepository.PersistNewItem() gets the sort order of any new node via:

var sortOrder = Database.ExecuteScalar("SELECT COUNT(*) FROM umbracoNode WHERE parentID = @ParentId AND nodeObjectType = @NodeObjectType", new { /ParentId =/ entity.ParentId, NodeObjectType = NodeObjectTypeId });

effectively setting the sort order to (number-of-children + 1). Meanwhile, ContentRepository.PersistDeletedItem() removes the deleted node without making any change to its siblings sort order.

So... if we do not want to reorder all children, PersistNewItem should set the sort order to (max(siblings-sort-order) + 1).

Damiaan Peeters 13 Jun 2015, 23:47:01

pull request: https://github.com/umbraco/Umbraco-CMS/pull/710

Stephan 15 Jun 2015, 12:50:11

(pull request beeing discussed)

Stephan 16 Jun 2015, 16:27:26

(pull request merged)

Priority: Normal

Type: Bug

State: Fixed

Assignee: Stephan

Difficulty: Normal


Backwards Compatible: True

Fix Submitted: Pull request

Affected versions: 7.1.8, 7.2.4, 7.2.5, 7.2.6

Due in version: 7.3.0


Story Points: