mirror of
https://github.com/django/django.git
synced 2025-10-27 07:36:08 +00:00
[1.5.x] Fixed prefetch_related + pickle regressions
There were a couple of regressions related to field pickling. The
regressions were introduced by QuerySet._known_related_objects caching.
The regressions aren't present in master, the fix was likely in
f403653cf1.
Fixed #20157, fixed #20257. Also made QuerySets with model=None
picklable.
This commit is contained in:
@@ -5,7 +5,8 @@ import datetime
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from .models import Group, Event, Happening
|
||||
from .models import Group, Event, Happening, Person, Post
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
|
||||
|
||||
class PickleabilityTestCase(TestCase):
|
||||
@@ -46,3 +47,29 @@ class PickleabilityTestCase(TestCase):
|
||||
# can't just use assertEqual(original, unpickled)
|
||||
self.assertEqual(original.__class__, unpickled.__class__)
|
||||
self.assertEqual(original.args, unpickled.args)
|
||||
|
||||
def test_pickle_m2m_prefetch_related(self):
|
||||
bob = Person(name="Bob")
|
||||
bob.save()
|
||||
people = Person.objects.prefetch_related('socialprofile_set')
|
||||
dumped = pickle.dumps(people)
|
||||
people = pickle.loads(dumped)
|
||||
self.assertQuerysetEqual(
|
||||
people, [bob], lambda x: x)
|
||||
|
||||
def test_pickle_field_default_prefetch_related(self):
|
||||
p1 = Post.objects.create()
|
||||
posts = Post.objects.prefetch_related('materials')
|
||||
dumped = pickle.dumps(posts)
|
||||
posts = pickle.loads(dumped)
|
||||
self.assertQuerysetEqual(
|
||||
posts, [p1], lambda x: x)
|
||||
|
||||
def test_pickle_emptyqs(self):
|
||||
u = AnonymousUser()
|
||||
# Use AnonymousUser, as AnonymousUser.groups has qs.model = None
|
||||
empty = u.groups.all()
|
||||
dumped = pickle.dumps(empty)
|
||||
empty = pickle.loads(dumped)
|
||||
self.assertQuerysetEqual(
|
||||
empty, [])
|
||||
|
||||
Reference in New Issue
Block a user