diff --git a/django/db/models/query.py b/django/db/models/query.py
index f69c775..9e18a3a 100644
a
|
b
|
class QuerySet(object):
|
204 | 204 | """ |
205 | 205 | Allows the QuerySet to be pickled. |
206 | 206 | """ |
207 | | # Force the cache to be fully populated. |
208 | | self._fetch_all() |
209 | 207 | obj_dict = self.__dict__.copy() |
210 | 208 | obj_dict[DJANGO_VERSION_PICKLE_KEY] = get_version() |
211 | 209 | return obj_dict |
diff --git a/tests/queryset_pickle/models.py b/tests/queryset_pickle/models.py
index 5e60963..da3896c 100644
a
|
b
|
class Container(object):
|
60 | 60 | |
61 | 61 | class M2MModel(models.Model): |
62 | 62 | groups = models.ManyToManyField(Group) |
| 63 | |
| 64 | |
| 65 | class Parent(models.Model): |
| 66 | name = models.CharField(max_length=64) |
| 67 | |
| 68 | |
| 69 | class Child(models.Model): |
| 70 | name = models.CharField(max_length=64) |
| 71 | parent = models.ForeignKey(Parent, on_delete=models.CASCADE) |
| 72 | No newline at end of file |
diff --git a/tests/queryset_pickle/tests.py b/tests/queryset_pickle/tests.py
index 1111a7f..27af90b 100644
a
|
b
|
from django.test import TestCase
|
9 | 9 | from django.utils import six |
10 | 10 | from django.utils.version import get_version |
11 | 11 | |
12 | | from .models import Container, Event, Group, Happening, M2MModel |
| 12 | from .models import Container, Event, Group, Happening, M2MModel, Parent, Child |
13 | 13 | |
14 | 14 | |
15 | 15 | class PickleabilityTestCase(TestCase): |
… |
… |
class PickleabilityTestCase(TestCase):
|
153 | 153 | msg = "Pickled queryset instance's Django version 1.0 does not match the current version %s." % get_version() |
154 | 154 | with self.assertRaisesMessage(RuntimeWarning, msg): |
155 | 155 | pickle.loads(pickle.dumps(qs)) |
| 156 | |
| 157 | def test_queryset_evaluation(self): |
| 158 | """ |
| 159 | #27159 -- Test that no unintentional queryset evaluation happens |
| 160 | """ |
| 161 | for i in range(1, 100000): |
| 162 | Parent(name='Parent {}'.format(i)).save() |
| 163 | |
| 164 | child = Child(name='Child 1', parent=Parent.objects.all()[0]) |
| 165 | |
| 166 | parents = Parent.objects.all() |
| 167 | children = Child.objects.filter(parent__in=parents) |
| 168 | |
| 169 | dumped = pickle.dumps(children.query) |
| 170 | # Assume that such a simple query is less than a megabyte pickled |
| 171 | self.assertLess(len(dumped), 1024 * 1024) |
| 172 | No newline at end of file |