mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	[4.0.x] Fixed #33008 -- Fixed prefetch_related() for deleted GenericForeignKeys.
Thanks Simon Charette for the implementation idea.
Backport of cc4cb95bef from main
			
			
This commit is contained in:
		
				
					committed by
					
						 Mariusz Felisiak
						Mariusz Felisiak
					
				
			
			
				
	
			
			
			
						parent
						
							8ab95364b5
						
					
				
				
					commit
					dd8945d361
				
			| @@ -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