Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Deleting a queryset of Contents does not call treebeard's custom delete method, causing tree inconsistencies #281

Open
gavinwahl opened this issue Dec 2, 2014 · 0 comments

Comments

@gavinwahl
Copy link
Member

Treebeard's MP_NodeQuerySet has a delete() method that handles deleting children and updating numchild counts in their parents. However, if delete() is called on a content, django's collector does try to delete that content's node (through GenericRelation), but it doesn't use treebeard's custom delete. This means that there is a hole in the tree, where a generation is skipped. This totally breaks prefetch_tree.

A failing test:

diff --git a/tests/modeltests/core_tests/tests/core.py b/tests/modeltests/core_tests/tests/core.py
index c15c586..fca14e6 100644
--- a/tests/modeltests/core_tests/tests/core.py
+++ b/tests/modeltests/core_tests/tests/core.py
@@ -260,6 +260,12 @@ class TestCore(RootNodeTestCase):
             self.assertEqual(widget.get_attributes(),
                              attributes)

+    def test_delete_queryset(self):
+        Layout.objects.all().delete()
+        self.assertFalse(Layout.objects.all().exists())
+        # deleting the content should also delete the node's children
+        self.assertFalse(Node.objects.all().exists())
+

 class TestRegistry(RootNodeTestCase):
     def setUp(self):
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant