1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

[soc2009/multidb] Correctly handle pickling of Query objects, restoring them to the correct database.

git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/multidb@11274 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Alex Gaynor
2009-07-20 18:52:47 +00:00
parent 502d4982c9
commit ac74fa7e32
6 changed files with 30 additions and 9 deletions

View File

@@ -1,4 +1,5 @@
import datetime
import pickle
from django.conf import settings
from django.db import connections
@@ -79,6 +80,15 @@ class QueryTestCase(TestCase):
months = Book.objects.dates('published', 'month').using(db)
self.assertEqual(sorted(o.month for o in months), [5, 12])
class PickleQuerySetTestCase(TestCase):
def test_pickling(self):
for db in connections:
qs = Book.objects.all()
self.assertEqual(qs.query.connection,
pickle.loads(pickle.dumps(qs)).query.connection)
self.assertEqual(qs._using, pickle.loads(pickle.dumps(qs))._using)
if len(settings.DATABASES) > 1:
class MetaUsingTestCase(TestCase):
def test_meta_using_queries(self):