mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #35967 -- Deferred test suite fixtures serialization after all dbs setup.
While the top-level objects fed to serialization are bound to the test database being created nothing prevents code invoked during serialization from performing queries against other connections entries that haven't been swapped yet. The reported example of that is a database router directing all reads to a test mirror for a set of models involving auto-created many-to-many fields. It might be tempting to address the many-to-many field case but this a symptom of a larger problem where the test framework yields the flow execution to user code that could interact with non-test databases in unexpected ways. Deferring test database fixture serialization until the point where all connections entries have been swapped for their test equivalent ensures that no code triggered during serialization can interact with non-test databases. Thanks Jake Howard for the report and Jacob Walls for the initial investigation.
This commit is contained in:
committed by
Mariusz Felisiak
parent
df2c4952df
commit
dc69a63f84
@@ -931,8 +931,9 @@ class SetupDatabasesTests(unittest.TestCase):
|
||||
with mock.patch("django.test.utils.connections", new=tested_connections):
|
||||
self.runner_instance.setup_databases()
|
||||
mocked_db_creation.return_value.create_test_db.assert_called_once_with(
|
||||
verbosity=0, autoclobber=False, serialize=True, keepdb=False
|
||||
verbosity=0, autoclobber=False, serialize=False, keepdb=False
|
||||
)
|
||||
mocked_db_creation.return_value.serialize_db_to_string.assert_called_once_with()
|
||||
|
||||
|
||||
@skipUnlessDBFeature("supports_sequence_reset")
|
||||
|
||||
Reference in New Issue
Block a user