sehughes / django-treebeard

Automatically exported from code.google.com/p/django-treebeard
Apache License 2.0
0 stars 0 forks source link

NS_Node.get_ancestors not always in the same order #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
First of all thanks for treebeard. 

I noticed node order is not guaranteed in NS_Node.get_ancestors. My view
worked as expected but anytime I changed something in admin I got
unexpected results when I did modelinstance.get_parent() (overriding save
in my subclass.). The fix is trivial (I think):

$ svn diff
Index: treebeard/ns_tree.py
===================================================================
--- treebeard/ns_tree.py        (revision 81)
+++ treebeard/ns_tree.py        (working copy)
@@ -718,7 +718,7 @@
         return self.__class__.objects.filter(
             tree_id=self.tree_id,
             lft__lt=self.lft,
-            rgt__gt=self.rgt)
+            rgt__gt=self.rgt).order_by('lft')

     def is_descendant_of(self, node):

Original issue reported on code.google.com by peter.va...@gmail.com on 11 Mar 2009 at 7:08

GoogleCodeExporter commented 9 years ago
Peter:

Are you redefining Meta in your subclass? You need to add "ordering = 
['tree_id', 'lft']" again in your subclass' 
Meta if you do.

Please let me know id this is the case since I can't reproduce this bug.

Original comment by gpicon on 14 Jun 2009 at 11:19

GoogleCodeExporter commented 9 years ago
Added a warning in the documentation, see http://django-
treebeard.googlecode.com/svn/docs/index.html#treebeard.ns_tree.NS_Node

Does the problem persist even with that?

Original comment by gpicon on 14 Jun 2009 at 11:43

GoogleCodeExporter commented 9 years ago

Original comment by gpicon on 14 Jun 2009 at 8:20

GoogleCodeExporter commented 9 years ago

Original comment by gpicon on 4 Oct 2009 at 1:21