summaryrefslogtreecommitdiff
path: root/tests/regressiontests/multiple_database/tests.py
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2010-03-07 07:13:55 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2010-03-07 07:13:55 +0000
commit18983f0ee73c9b3708b10b90e0a37bd17a8a1729 (patch)
tree7d9c222d47c132f3cc773addaba6f6efa21c8890 /tests/regressiontests/multiple_database/tests.py
parent3508a86ddf86da7a6b1444f89217e45b3514c722 (diff)
Fixed #13003 -- Ensured that ._state.db is set correctly for select_related() queries. Thanks to Alex Gaynor for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12701 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/multiple_database/tests.py')
-rw-r--r--tests/regressiontests/multiple_database/tests.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/regressiontests/multiple_database/tests.py b/tests/regressiontests/multiple_database/tests.py
index 47ea010045..81b6a5ffb9 100644
--- a/tests/regressiontests/multiple_database/tests.py
+++ b/tests/regressiontests/multiple_database/tests.py
@@ -641,6 +641,20 @@ class QueryTestCase(TestCase):
val = Book.objects.raw('SELECT id FROM "multiple_database_book"').using('other')
self.assertEqual(map(lambda o: o.pk, val), [dive.pk])
+ def test_select_related(self):
+ "Database assignment is retained if an object is retrieved with select_related()"
+ # Create a book and author on the other database
+ mark = Person.objects.using('other').create(name="Mark Pilgrim")
+ dive = Book.objects.using('other').create(title="Dive into Python",
+ published=datetime.date(2009, 5, 4),
+ editor=mark)
+
+ # Retrieve the Person using select_related()
+ book = Book.objects.using('other').select_related('editor').get(title="Dive into Python")
+
+ # The editor instance should have a db state
+ self.assertEqual(book.editor._state.db, 'other')
+
class TestRouter(object):
# A test router. The behaviour is vaguely master/slave, but the
# databases aren't assumed to propagate changes.