Issue #52 wontfix

Overriding objects breaks some methods

spool avatarspool 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

    Right:

    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 Picon

    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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.