Refs #31169 -- Added DatabaseCreation.setup_worker_connection() hook.

This commit is contained in:
Valz 2022-02-23 11:34:22 +01:00 committed by Mariusz Felisiak
parent eabc22f919
commit ae91ecf6a1
2 changed files with 11 additions and 7 deletions

View File

@ -369,3 +369,13 @@ class BaseDatabaseCreation:
settings_dict["ENGINE"],
self._get_test_db_name(),
)
def setup_worker_connection(self, _worker_id):
settings_dict = self.get_test_db_clone_settings(str(_worker_id))
# connection.settings_dict must be updated in place for changes to be
# reflected in django.db.connections. If the following line assigned
# connection.settings_dict = settings_dict, new threads would connect
# to the default database instead of the appropriate clone.
self.connection.settings_dict.update(settings_dict)
self.mark_expected_failures_and_skips()
self.connection.close()

View File

@ -407,13 +407,7 @@ def _init_worker(counter):
for alias in connections:
connection = connections[alias]
settings_dict = connection.creation.get_test_db_clone_settings(str(_worker_id))
# connection.settings_dict must be updated in place for changes to be
# reflected in django.db.connections. If the following line assigned
# connection.settings_dict = settings_dict, new threads would connect
# to the default database instead of the appropriate clone.
connection.settings_dict.update(settings_dict)
connection.close()
connection.creation.setup_worker_connection(_worker_id)
def _run_subsuite(args):