Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add first child if there's no last child #235

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions treebeard/mp_tree.py
Expand Up @@ -362,7 +362,8 @@ def process(self):
newobj = self.node_cls(**self.kwargs)

newobj.depth = self.node.depth + 1
if self.node.is_leaf():
last_child = self.node.get_last_child()
if last_child is None:
# the node had no children, adding the first child
newobj.path = self.node_cls._get_path(
self.node.path, newobj.depth, 1)
Expand All @@ -374,7 +375,7 @@ def process(self):
' and UPDATE your database'))
else:
# adding the new child as the last one
newobj.path = self.node.get_last_child()._inc_path()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like what's happening here is the self.numchild attribute has been updated but the database doesn't have the child there

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

newobj.path = last_child._inc_path()

get_result_class(self.node_cls).objects.filter(
path=self.node.path).update(numchild=F('numchild')+1)
Expand Down