From 4c4954a3c133e824390296f6bb444622a8b25331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anssi=20K=C3=A4=C3=A4ri=C3=A4inen?= Date: Sat, 14 Sep 2013 10:33:12 +0300 Subject: [PATCH] [1.6.x] Added tests for double-pickling a QuerySet Refs #21102. Backpatch of 74b91b3888383fca28dea00e0e1ffb5aecec7c0f --- tests/queryset_pickle/tests.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/queryset_pickle/tests.py b/tests/queryset_pickle/tests.py index b4b540c80d5..58654977c3f 100644 --- a/tests/queryset_pickle/tests.py +++ b/tests/queryset_pickle/tests.py @@ -90,3 +90,15 @@ class PickleabilityTestCase(TestCase): reloaded = pickle.loads(dumped) self.assertEqual(original, reloaded) self.assertIs(reloaded.__class__, dynclass) + + def test_pickle_prefetch_related_idempotence(self): + g = Group.objects.create(name='foo') + groups = Group.objects.prefetch_related('event_set') + + # First pickling + groups = pickle.loads(pickle.dumps(groups)) + self.assertQuerysetEqual(groups, [g], lambda x: x) + + # Second pickling + groups = pickle.loads(pickle.dumps(groups)) + self.assertQuerysetEqual(groups, [g], lambda x: x)