mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Added more tests for pickling Prefetches with QuerySets.
This commit is contained in:
		| @@ -115,6 +115,25 @@ class PickleabilityTestCase(TestCase): | ||||
|         groups = pickle.loads(pickle.dumps(groups)) | ||||
|         self.assertSequenceEqual(groups, [g]) | ||||
|  | ||||
|     def test_pickle_prefetch_queryset_usable_outside_of_prefetch(self): | ||||
|         # Prefetch shouldn't affect the fetch-on-pickle behavior of the | ||||
|         # queryset passed to it. | ||||
|         Group.objects.create(name='foo') | ||||
|         events = Event.objects.order_by('id') | ||||
|         Group.objects.prefetch_related(models.Prefetch('event_set', queryset=events)) | ||||
|         with self.assertNumQueries(1): | ||||
|             events2 = pickle.loads(pickle.dumps(events)) | ||||
|         with self.assertNumQueries(0): | ||||
|             list(events2) | ||||
|  | ||||
|     def test_pickle_prefetch_queryset_still_usable(self): | ||||
|         g = Group.objects.create(name='foo') | ||||
|         groups = Group.objects.prefetch_related( | ||||
|             models.Prefetch('event_set', queryset=Event.objects.order_by('id')) | ||||
|         ) | ||||
|         groups2 = pickle.loads(pickle.dumps(groups)) | ||||
|         self.assertSequenceEqual(groups2.filter(id__gte=0), [g]) | ||||
|  | ||||
|     def test_pickle_prefetch_related_with_m2m_and_objects_deletion(self): | ||||
|         """ | ||||
|         #24831 -- Cached properties on ManyToOneRel created in QuerySet.delete() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user