#19149: Generic Relation not cascading with Multi table inheritance.
-------------------------------------+-------------------------------------
     Reporter:  thomaspurchas        |                    Owner:  nicolas
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |               Resolution:
     Severity:  Normal               |             Triage Stage:  Accepted
     Keywords:  multitable,          |      Needs documentation:  0
  inheritance, genericforeignkey     |  Patch needs improvement:  1
    Has patch:  1                    |                    UI/UX:  0
  Needs tests:  0                    |
Easy pickings:  0                    |
-------------------------------------+-------------------------------------

Comment (by akaariai):

 The patch doesn't work correctly for parent model associations. I modified
 the test case to this:
 {{{
     def test_inherited_models_delete(self):
         """
         Test that when deleting a class that inherits a GenericRelation,
         the correct related object is deleted on cascade.
         """
         p = Post.objects.create(title="This is a title",
             description="This is a description")
         ppost = ParentPost.objects.get(pk=p.pk)
         t1 = TaggedItem.objects.create(content_object=p, tag="This is a
 tag")
         t2 = TaggedItem.objects.create(content_object=ppost,
                                        tag="This is anoter tag")
         ppost_ct = ContentType.objects.get_for_model(ParentPost)
         self.assertEqual(list(TaggedItem.objects.all().order_by('tag')),
                          [t1, t2])
         self.assertEqual(
             list(TaggedItem.objects.filter(content_type=ppost_ct)),
             [t2])
         self.assertEqual(list(Post.objects.all()), [p])
         p.delete()
         self.assertEqual(list(TaggedItem.objects.all()), [])
 }}}

 The last line doesn't pass - the parent model's taggeditem isn't deleted.
 So, the patch just moves the problem around. At minimum both parent and
 child model deletion should delete the taggeditems for both parent and
 child.

 There are more problems in parent <-> child deletions in general If there
 are more than one child for a parent and you delete one of the childs,
 then the other childs will not be deleted. Also, each parent model
 retrieval executes a separate query. A more generic solution to all of the
 problems would be welcome, though just solving this ticket's issue is a
 good approach, too...

-- 
Ticket URL: <https://code.djangoproject.com/ticket/19149#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to