From 49ca6bbc445cb75ee742b215f5f90465ad8e7309 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Mon, 5 Jul 2021 15:22:08 +0200 Subject: [PATCH] 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. --- tests/multiple_database/tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/multiple_database/tests.py b/tests/multiple_database/tests.py index 2a6a725472..946137dc12 100644 --- a/tests/multiple_database/tests.py +++ b/tests/multiple_database/tests.py @@ -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):