mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed transaction handling for a number of operations on related objects.
Thanks Anssi and Aymeric for the reviews. Refs #21174.
This commit is contained in:
parent
975337e5c3
commit
bc9be72bdc
5 changed files with 124 additions and 79 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue