From bc9be72bdc9bb4dfc7f967ac3856115f0a6166b8 Mon Sep 17 00:00:00 2001 From: Loic Bistuer Date: Sun, 30 Mar 2014 01:57:28 +0700 Subject: Fixed transaction handling for a number of operations on related objects. Thanks Anssi and Aymeric for the reviews. Refs #21174. --- tests/multiple_database/tests.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'tests/multiple_database') 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 -- cgit v1.3