1. Gustavo Picón
  2. django-treebeard
  3. Issues
Issue #52 wontfix

Overriding objects breaks some methods

created an issue

Hi, my work machine isn't ssh-able atm, but as of this afternoon I believe I have determined that some of the node adding methods, in particular addding new roots in the MPTT class (and given one of the queue patches possibly NS) assumes the correct ordering is on the manager that objects is set to.

If you use (as I do) a geodjango mixin with MPTT and are using the GeoManager Manager to allow for spatial queries, basic methods like adding root nodes will fail because the get_root_nodes() method assumes the correct ordering is used on MyModel.objects. I think possibly the safest solution (and the one suggested in the currently queued branch) is to enforce (potentially redundant) ordering on the relevant methods.

I should have proper test case for you tomorrow, but in case you see this before then and want to fix it, thought I'd get the bug out now. Thanks for an excellent project: my thesis depends on it :)

Comments (2)

  1. spool reporter


    class Meta:
        ordering = ['path']

    fixes it, as I suspected (for the mptt case). Liberal use of order_by('path') in the mptt class. I've got a project to finish now, but hopefully I can have my branch sorted so you can pull from it (with tests and all)! In the meantime, anyone using treebeard without the provided manager needs to enforce ordering themselves.

    Do have a look at themax.ru's branch, which I believe fixes this for the NS case.

  2. Gustavo Picón repo owner

    Hi spool,

    I think you refer to Materialized Path (MP). MPTT is another way to refer to Nested Sets (NS).

    On the bug report, the test suite is already making sure that the ordering is working. Usually when something like this happen, is because the ordering was overridden by Meta (like in your second comment) or replaced the manager.

    Note in the code that we depend on a custom manager to guarantee the ordering. If you replace the manager in your subclass (objects = ...), then tree beard's ordering won't work. This should probably be displayed with more emphasis in the documentation.

    Good luck with your thesis!

    - tabo

  3. Log in to comment