Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #7813 -- Allow pickling of Query classes that use select_relate…

…d().

Based on a patch from Justin Bronn.

The test in this patch most likely breaks on Oracle. That's another issue.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@8053 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 8745beccb10f60864910b7941d7d0c99a5db30ed 1 parent 83e97ec
@malcolmt malcolmt authored
View
2  django/db/models/sql/query.py
@@ -106,6 +106,8 @@ def __getstate__(self):
Pickling support.
"""
obj_dict = self.__dict__.copy()
+ obj_dict['related_select_fields'] = []
+ obj_dict['related_select_cols'] = []
del obj_dict['connection']
return obj_dict
View
9 tests/regressiontests/queries/models.py
@@ -785,6 +785,15 @@ class Related(models.Model):
this doesn't crash, it's a Good Thing.
>>> out = pickle.dumps(Item.objects.all())
+We should also be able to pickle things that use select_related(). The only
+tricky thing here is to ensure that we do the related selections properly after
+unpickling.
+>>> qs = Item.objects.select_related()
+>>> query = qs.query.as_sql()[0]
+>>> query2 = pickle.loads(pickle.dumps(qs.query))
+>>> query2.as_sql()[0] == query
+True
+
Bug #7277
>>> ann1 = Annotation.objects.create(name='a1', tag=t1)
>>> ann1.notes.add(n1)
Please sign in to comment.
Something went wrong with that request. Please try again.