mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #33008 -- Fixed prefetch_related() for deleted GenericForeignKeys.
Thanks Simon Charette for the implementation idea.
This commit is contained in:
committed by
Mariusz Felisiak
parent
cdad96e633
commit
cc4cb95bef
@@ -1033,6 +1033,24 @@ class GenericRelationTests(TestCase):
|
||||
# instance returned by the manager.
|
||||
self.assertEqual(list(bookmark.tags.all()), list(bookmark.tags.all().all()))
|
||||
|
||||
def test_deleted_GFK(self):
|
||||
TaggedItem.objects.create(tag='awesome', content_object=self.book1)
|
||||
TaggedItem.objects.create(tag='awesome', content_object=self.book2)
|
||||
ct = ContentType.objects.get_for_model(Book)
|
||||
|
||||
book1_pk = self.book1.pk
|
||||
self.book1.delete()
|
||||
|
||||
with self.assertNumQueries(2):
|
||||
qs = TaggedItem.objects.filter(tag='awesome').prefetch_related('content_object')
|
||||
result = [
|
||||
(tag.object_id, tag.content_type_id, tag.content_object) for tag in qs
|
||||
]
|
||||
self.assertEqual(result, [
|
||||
(book1_pk, ct.pk, None),
|
||||
(self.book2.pk, ct.pk, self.book2),
|
||||
])
|
||||
|
||||
|
||||
class MultiTableInheritanceTest(TestCase):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user