From ae91ecf6a1037fb67d14841b66ac19d4c2ccc4ac Mon Sep 17 00:00:00 2001 From: Valz Date: Wed, 23 Feb 2022 11:34:22 +0100 Subject: [PATCH] Refs #31169 -- Added DatabaseCreation.setup_worker_connection() hook. --- django/db/backends/base/creation.py | 10 ++++++++++ django/test/runner.py | 8 +------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/django/db/backends/base/creation.py b/django/db/backends/base/creation.py index 78480fc0f8..15c2167be4 100644 --- a/django/db/backends/base/creation.py +++ b/django/db/backends/base/creation.py @@ -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() diff --git a/django/test/runner.py b/django/test/runner.py index 113d5216a6..aba515e735 100644 --- a/django/test/runner.py +++ b/django/test/runner.py @@ -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):