Fixed isolation of RouterTestCase.test_m2m_cross_database_protection().

Hardcoded pks are necessary for this test case, however we need to set
them for all new rows because the sequence will not increment
automatically. It works when the sequence is incremented by other
test cases.
This commit is contained in:
Mariusz Felisiak 2021-07-05 15:22:08 +02:00 committed by GitHub
parent edde2a0699
commit 49ca6bbc44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -1344,14 +1344,14 @@ class RouterTestCase(TestCase):
# If you create an object through a M2M relation, it will be
# written to the write database, even if the original object
# was on the read database
alice = dive.authors.create(name='Alice')
alice = dive.authors.create(name='Alice', pk=3)
self.assertEqual(alice._state.db, 'default')
# Same goes for get_or_create, regardless of whether getting or creating
alice, created = dive.authors.get_or_create(name='Alice')
self.assertEqual(alice._state.db, 'default')
bob, created = dive.authors.get_or_create(name='Bob')
bob, created = dive.authors.get_or_create(name='Bob', defaults={'pk': 4})
self.assertEqual(bob._state.db, 'default')
def test_o2o_cross_database_protection(self):