summaryrefslogtreecommitdiff
path: root/tests/queryset_pickle
diff options
context:
space:
mode:
authorAdam Chainz <adam@adamj.eu>2016-11-23 14:59:43 +0000
committerTim Graham <timograham@gmail.com>2016-11-23 11:18:34 -0500
commit7dd315a46f8e9a6fdb904424542c6f67a57edfa3 (patch)
tree53906544ef80719e03a3bbfa2de7dd79980bfa3a /tests/queryset_pickle
parent2e5fbe889f02c74ab8c153043f22ccce96230716 (diff)
downloaddjango-7dd315a46f8e9a6fdb904424542c6f67a57edfa3.tar.gz
Added more tests for pickling Prefetches with QuerySets.
Diffstat (limited to 'tests/queryset_pickle')
-rw-r--r--tests/queryset_pickle/tests.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/queryset_pickle/tests.py b/tests/queryset_pickle/tests.py
index 86daebfaf9..37069cf286 100644
--- a/tests/queryset_pickle/tests.py
+++ b/tests/queryset_pickle/tests.py
@@ -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()