Issue 32: Updating nodes causes incorrect MPTT fields on other nodes
Status:  Duplicate
Merged:  issue 78
Owner:
Closed:  Nov 2010
Reported by eallik, Sep 9, 2008
I have:

        mptt.register(ContentNode, order_insertion_by=['order'])

and the following doctest:

        >>> english_node = ContentNode(slug='en', title='English')
        >>> english_node.save()
        >>> about_node = ContentNode(slug='about', title='About', parent=english_node, order=1)
        >>> about_node.save()
        >>> contact_node = ContentNode(slug='contact', title='Contact', parent=english_node, order=2)
        >>> contact_node.save()
        >>> english_node = ContentNode.objects.get(pk=english_node.pk) # Refresh, otherwise get_children() returns []
        >>> english_node.get_children()
        [<ContentNode: "About">, <ContentNode: "Contact">]

that is failing with:

        Failed example:
            english_node.get_children()
        Expected:
            [<ContentNode: "About">, <ContentNode: "Contact">]
        Got:
            [<ContentNode: "Contact">, <ContentNode: "About">]

Even though Contact has order=2 About has order=1.

Oct 12, 2008
Project Member #1 jonathan.buchanan
This is the same thing I saw when I fixed the tests in revision 110 - the problem is
that English node still has a lft of 1 and a rght of 2 when you're inserting the
second child, as the first child has only done an UPDATE for english_node in the
database.

Refreshing english_node from the database before the second insertion should fix it.

In my case, having diagnosed what was wrong with the tests, I have no idea how they
ever worked! I could possibly do something to try and update the lft and right of a
parent node when adding a new child, so I'll not close this yet.
Status: Chatting
Owner: jonathan.buchanan
Oct 30, 2008
#2 rockmhow...@gmail.com
The same problem occurs if you are not using an explicit order field.

In order to get this to work properly for the "no order field" case, I have to create
the contact_node without a parent and then call:

ContentNode.tree.insert_node(contact_node,about_node,position="right",commit=True)

Using insert_node to attach to the english_node with position="last_child" fails the
same way that ot does in your example.

Sep 3, 2010
Project Member #3 craig.ds@gmail.com
(No comment was entered for this change.)
Summary: Updating nodes causes incorrect MPTT fields on other nodes
Status: Accepted
Owner: craig.ds
Nov 12, 2010
Project Member #4 craig.ds@gmail.com
(No comment was entered for this change.)
Status: Duplicate
Mergedinto: 78