From adc0c4fbac98f9cb975e8fa8220323b2de638b46 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Sat, 14 Mar 2015 21:25:33 -0400 Subject: Fixed #18556 -- Allowed RelatedManager.add() to execute 1 query where possible. Thanks Loic Bistuer for review. --- tests/multiple_database/tests.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'tests/multiple_database') diff --git a/tests/multiple_database/tests.py b/tests/multiple_database/tests.py index 08493ffaf2..4354217d57 100644 --- a/tests/multiple_database/tests.py +++ b/tests/multiple_database/tests.py @@ -1043,6 +1043,17 @@ class RouterTestCase(TestCase): self.assertEqual(Book.objects.using('default').count(), 1) self.assertEqual(Book.objects.using('other').count(), 1) + def test_invalid_set_foreign_key_assignment(self): + marty = Person.objects.using('default').create(name="Marty Alchin") + dive = Book.objects.using('other').create( + title="Dive into Python", + published=datetime.date(2009, 5, 4), + ) + # Set a foreign key set with an object from a different database + msg = " instance isn't saved. Use bulk=False or save the object first." + with self.assertRaisesMessage(ValueError, msg): + marty.edited.set([dive]) + def test_foreign_key_cross_database_protection(self): "Foreign keys can cross databases if they two databases have a common source" # Create a book and author on the default database @@ -1085,7 +1096,7 @@ class RouterTestCase(TestCase): # Set a foreign key set with an object from a different database try: - marty.edited = [pro, dive] + marty.edited.set([pro, dive], bulk=False) except ValueError: self.fail("Assignment across primary/replica databases with a common source should be ok") @@ -1107,7 +1118,7 @@ class RouterTestCase(TestCase): # Add to a foreign key set with an object from a different database try: - marty.edited.add(dive) + marty.edited.add(dive, bulk=False) except ValueError: self.fail("Assignment across primary/replica databases with a common source should be ok") -- cgit v1.3