tabo/django-treebeard — pull request #5 by danielquinn (2013-01-12 23:02:20+00:00)
Title: Added .order_by() to get_root_nodes

Treebeard works great unless you're working off of an database import that inserted the records out of sequential order, then suddenly `cls.objects.filter(depth=1)` doesn't return a list of paths with the most recent one on the end... something you need when you're trying to get the `last_root`.

Without this patch, projects with the aforementioned database import will often suffer from `duplicate key value violates unique constraint` complaints during .add_root(), as Treebeard unintentionally attempts to add a new root where one already exists.