1. Gustavo Picon
  2. django-treebeard
Issue #43 invalid

is_descendant_of error when moving nodes

Rob Hudson
created an issue

Copy/Paste error:

{{{ Traceback: File "/opt/virtualenvs/eap/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response 100. response = callback(request, callback_args, callback_kwargs) File "/opt/virtualenvs/eap/lib/python2.6/site-packages/django/contrib/admin/options.py" in wrapper 265. return self.admin_site.admin_view(view)(*args, kwargs) File "/opt/virtualenvs/eap/lib/python2.6/site-packages/django/utils/decorators.py" in _wrapped_view 76. response = view_func(request, args, kwargs) File "/opt/virtualenvs/eap/lib/python2.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func 78. response = view_func(request, *args, kwargs) File "/opt/virtualenvs/eap/lib/python2.6/site-packages/django/contrib/admin/sites.py" in inner 190. return view(request, args, kwargs) File "/opt/virtualenvs/eap/lib/python2.6/site-packages/django/utils/decorators.py" in _wrapper 21. return decorator(bound_func)(*args, kwargs) File "/opt/virtualenvs/eap/lib/python2.6/site-packages/django/utils/decorators.py" in _wrapped_view 76. response = view_func(request, args, kwargs) File "/opt/virtualenvs/eap/lib/python2.6/site-packages/django/utils/decorators.py" in bound_func 17. return func(self, *args2, kwargs2) File "/opt/virtualenvs/eap/lib/python2.6/site-packages/django/db/transaction.py" in _commit_on_success 299. res = func(args, *kw) File "/opt/virtualenvs/eap/lib/python2.6/site-packages/django/contrib/admin/options.py" in change_view 903. new_object = self.save_form(request, form, change=True) File "/opt/virtualenvs/eap/lib/python2.6/site-packages/django/contrib/admin/options.py" in save_form 617. return form.save(commit=False) File "/opt/virtualenvs/eap/src/django-treebeard-tip/treebeard/forms.py" in save 151. self.instance.move(reference_node, pos=position_type) File "/opt/virtualenvs/eap/src/django-treebeard-tip/treebeard/ns_tree.py" in move 307. if target.is_descendant_of(self):

Exception Type: AttributeError at /admin/keiko/modulepage/14/ Exception Value: 'NoneType' object has no attribute 'is_descendant_of' }}}

The 2nd to last stack has these local variables:

{{{ commit: False position_type: u'first-child' reference_node: <ModulePage: m-1000 -> m-1000> reference_node_id: 13 self: <django.forms.models.ModulePageForm object at 0x555557c5ca90> }}}

The last stack has these local variables:

{{{ cls: <class 'web.keiko.models.ModulePage'> parent: None pos: 'first-sibling' self: <ModulePage: m-1000 -> m-1005> target: None }}}

It looks like an edge case when trying to move a sibling into the root (top) node?

Comments (5)

  1. Gustavo Picon repo owner
    • changed status to open

    Rob:

    Your tree is inconsistent.

    Could you please send me this for analysis?

    [(x.id, x.tree_id, x.lft, x.rgt, x.depth) for x in web.keiko.models.ModulePage.objects.all()]
    

    Basically what is hapenning in NS_Node.save() is that the target node is NOT a leaf (rgt-lft>1), but then there are no child nodes (lft<>rgt in the interval and depth=depth+1). We need find_problems/fix_tree for NS nodes too.

  2. Leo Chan

    I encountered a similar issue too. Not sure if it is same as the above issue. But I see the same error message. I did a nodeA.move(nodeB,pos='last-child') The issue only happens periodically. Especially when I move many nodes in the same script. Every time it happens, len(nodeB.get_children()) is 0 but nodeB.is_leaf() is false. The issue no longer happens if if I do a nodeA.save() and nodeB.save() after each move(). I guess it is something to do with db transactions.

  3. Leo Chan

    In mp_tree.py, MP_Node.move()

    The last line is transaction.commit_unless_managed() That function is deprecated in django 1.7 Would that be the issue?

  4. Log in to comment