diff options
author | Loic Bistuer <loic.bistuer@gmail.com> | 2014-03-30 01:57:28 +0700 |
---|---|---|
committer | Loic Bistuer <loic.bistuer@gmail.com> | 2014-03-30 12:13:00 +0700 |
commit | bc9be72bdc9bb4dfc7f967ac3856115f0a6166b8 (patch) | |
tree | 04a4a68821d1ba243f4ad7841ebc80da400f591a /tests/multiple_database | |
parent | 975337e5c348a770df5a1925ce256ab54cb8c529 (diff) | |
download | django-bc9be72bdc9bb4dfc7f967ac3856115f0a6166b8.tar.gz |
Fixed transaction handling for a number of operations on related objects.
Thanks Anssi and Aymeric for the reviews. Refs #21174.
Diffstat (limited to 'tests/multiple_database')
-rw-r--r-- | tests/multiple_database/tests.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/tests/multiple_database/tests.py b/tests/multiple_database/tests.py index cf225dbf36..01c6e1ef15 100644 --- a/tests/multiple_database/tests.py +++ b/tests/multiple_database/tests.py @@ -295,19 +295,23 @@ class QueryTestCase(TestCase): # Add to an m2m with an object from a different database with self.assertRaises(ValueError): - marty.book_set.add(dive) + with transaction.atomic(using='default'): + marty.book_set.add(dive) # Set a m2m with an object from a different database with self.assertRaises(ValueError): - marty.book_set = [pro, dive] + with transaction.atomic(using='default'): + marty.book_set = [pro, dive] # Add to a reverse m2m with an object from a different database with self.assertRaises(ValueError): - dive.authors.add(marty) + with transaction.atomic(using='other'): + dive.authors.add(marty) # Set a reverse m2m with an object from a different database with self.assertRaises(ValueError): - dive.authors = [mark, marty] + with transaction.atomic(using='other'): + dive.authors = [mark, marty] def test_m2m_deletion(self): "Cascaded deletions of m2m relations issue queries on the right database" @@ -762,7 +766,8 @@ class QueryTestCase(TestCase): # Add to a foreign key set with an object from a different database with self.assertRaises(ValueError): - dive.reviews.add(review1) + with transaction.atomic(using='other'): + dive.reviews.add(review1) # BUT! if you assign a FK object when the base object hasn't # been saved yet, you implicitly assign the database for the |