diff options
author | Tim Graham <timograham@gmail.com> | 2015-03-14 21:25:33 -0400 |
---|---|---|
committer | Loïc Bistuer <loic.bistuer@gmail.com> | 2015-07-28 09:28:25 +0700 |
commit | adc0c4fbac98f9cb975e8fa8220323b2de638b46 (patch) | |
tree | 6d00b444423b09a764fa3eb7d5b9f278c6531c0e /tests/multiple_database | |
parent | c2e70f02653519db3a49cd48f5158ccad7434d25 (diff) | |
download | django-adc0c4fbac98f9cb975e8fa8220323b2de638b46.tar.gz |
Fixed #18556 -- Allowed RelatedManager.add() to execute 1 query where possible.
Thanks Loic Bistuer for review.
Diffstat (limited to 'tests/multiple_database')
-rw-r--r-- | tests/multiple_database/tests.py | 15 |
1 files changed, 13 insertions, 2 deletions
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 = "<Book: Dive into Python> 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") |