From 18983f0ee73c9b3708b10b90e0a37bd17a8a1729 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Sun, 7 Mar 2010 07:13:55 +0000 Subject: 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 --- tests/regressiontests/multiple_database/tests.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests/regressiontests/multiple_database') 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. -- cgit v1.3