From 99e65d648842d4715f32682117adc01223fef316 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Mon, 11 Sep 2017 08:32:40 -0700 Subject: [PATCH] Fixed #28578 -- Renamed DatabaseCreation number arguments to suffix. --- django/db/backends/base/creation.py | 16 ++++++++-------- django/db/backends/mysql/creation.py | 4 ++-- django/db/backends/postgresql/creation.py | 4 ++-- django/db/backends/sqlite3/creation.py | 8 ++++---- django/test/runner.py | 2 +- django/test/utils.py | 4 ++-- docs/releases/2.0.txt | 6 ++++++ 7 files changed, 25 insertions(+), 19 deletions(-) diff --git a/django/db/backends/base/creation.py b/django/db/backends/base/creation.py index 7158ff62576..1b2542a9f51 100644 --- a/django/db/backends/base/creation.py +++ b/django/db/backends/base/creation.py @@ -194,7 +194,7 @@ class BaseDatabaseCreation: return test_database_name - def clone_test_db(self, number, verbosity=1, autoclobber=False, keepdb=False): + def clone_test_db(self, suffix, verbosity=1, autoclobber=False, keepdb=False): """ Clone a test database. """ @@ -211,9 +211,9 @@ class BaseDatabaseCreation: # We could skip this call if keepdb is True, but we instead # give it the keepdb param. See create_test_db for details. - self._clone_test_db(number, verbosity, keepdb) + self._clone_test_db(suffix, verbosity, keepdb) - def get_test_db_clone_settings(self, number): + def get_test_db_clone_settings(self, suffix): """ Return a modified connection settings dict for the n-th clone of a DB. """ @@ -222,10 +222,10 @@ class BaseDatabaseCreation: # we don't need to call _get_test_db_name. orig_settings_dict = self.connection.settings_dict new_settings_dict = orig_settings_dict.copy() - new_settings_dict['NAME'] = '{}_{}'.format(orig_settings_dict['NAME'], number) + new_settings_dict['NAME'] = '{}_{}'.format(orig_settings_dict['NAME'], suffix) return new_settings_dict - def _clone_test_db(self, number, verbosity, keepdb=False): + def _clone_test_db(self, suffix, verbosity, keepdb=False): """ Internal implementation - duplicate the test db tables. """ @@ -233,16 +233,16 @@ class BaseDatabaseCreation: "The database backend doesn't support cloning databases. " "Disable the option to run tests in parallel processes.") - def destroy_test_db(self, old_database_name=None, verbosity=1, keepdb=False, number=None): + def destroy_test_db(self, old_database_name=None, verbosity=1, keepdb=False, suffix=None): """ Destroy a test database, prompting the user for confirmation if the database already exists. """ self.connection.close() - if number is None: + if suffix is None: test_database_name = self.connection.settings_dict['NAME'] else: - test_database_name = self.get_test_db_clone_settings(number)['NAME'] + test_database_name = self.get_test_db_clone_settings(suffix)['NAME'] if verbosity >= 1: action = 'Destroying' diff --git a/django/db/backends/mysql/creation.py b/django/db/backends/mysql/creation.py index 546fb6a6295..190d5cc5644 100644 --- a/django/db/backends/mysql/creation.py +++ b/django/db/backends/mysql/creation.py @@ -38,9 +38,9 @@ class DatabaseCreation(BaseDatabaseCreation): else: raise e - def _clone_test_db(self, number, verbosity, keepdb=False): + def _clone_test_db(self, suffix, verbosity, keepdb=False): source_database_name = self.connection.settings_dict['NAME'] - target_database_name = self.get_test_db_clone_settings(number)['NAME'] + target_database_name = self.get_test_db_clone_settings(suffix)['NAME'] test_db_params = { 'dbname': self.connection.ops.quote_name(target_database_name), 'suffix': self.sql_table_creation_suffix(), diff --git a/django/db/backends/postgresql/creation.py b/django/db/backends/postgresql/creation.py index a233758eea9..a93bdbb4a13 100644 --- a/django/db/backends/postgresql/creation.py +++ b/django/db/backends/postgresql/creation.py @@ -43,13 +43,13 @@ class DatabaseCreation(BaseDatabaseCreation): # exists". raise e - def _clone_test_db(self, number, verbosity, keepdb=False): + def _clone_test_db(self, suffix, verbosity, keepdb=False): # CREATE DATABASE ... WITH TEMPLATE ... requires closing connections # to the template database. self.connection.close() source_database_name = self.connection.settings_dict['NAME'] - target_database_name = self.get_test_db_clone_settings(number)['NAME'] + target_database_name = self.get_test_db_clone_settings(suffix)['NAME'] test_db_params = { 'dbname': self._quote_name(target_database_name), 'suffix': self._get_database_create_suffix(template=source_database_name), diff --git a/django/db/backends/sqlite3/creation.py b/django/db/backends/sqlite3/creation.py index 9a1b288bf2c..5cde383108b 100644 --- a/django/db/backends/sqlite3/creation.py +++ b/django/db/backends/sqlite3/creation.py @@ -56,7 +56,7 @@ class DatabaseCreation(BaseDatabaseCreation): sys.exit(1) return test_database_name - def get_test_db_clone_settings(self, number): + def get_test_db_clone_settings(self, suffix): orig_settings_dict = self.connection.settings_dict source_database_name = orig_settings_dict['NAME'] if self.is_in_memory_db(source_database_name): @@ -64,12 +64,12 @@ class DatabaseCreation(BaseDatabaseCreation): else: new_settings_dict = orig_settings_dict.copy() root, ext = os.path.splitext(orig_settings_dict['NAME']) - new_settings_dict['NAME'] = '{}_{}.{}'.format(root, number, ext) + new_settings_dict['NAME'] = '{}_{}.{}'.format(root, suffix, ext) return new_settings_dict - def _clone_test_db(self, number, verbosity, keepdb=False): + def _clone_test_db(self, suffix, verbosity, keepdb=False): source_database_name = self.connection.settings_dict['NAME'] - target_database_name = self.get_test_db_clone_settings(number)['NAME'] + target_database_name = self.get_test_db_clone_settings(suffix)['NAME'] # Forking automatically makes a copy of an in-memory database. if not self.is_in_memory_db(source_database_name): # Erase the old test database diff --git a/django/test/runner.py b/django/test/runner.py index e0169e6b5fc..672c98b8cda 100644 --- a/django/test/runner.py +++ b/django/test/runner.py @@ -290,7 +290,7 @@ def _init_worker(counter): for alias in connections: connection = connections[alias] - settings_dict = connection.creation.get_test_db_clone_settings(_worker_id) + 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 diff --git a/django/test/utils.py b/django/test/utils.py index f86b41ae518..fc783a4fc85 100644 --- a/django/test/utils.py +++ b/django/test/utils.py @@ -178,7 +178,7 @@ def setup_databases(verbosity, interactive, keepdb=False, debug_sql=False, paral if parallel > 1: for index in range(parallel): connection.creation.clone_test_db( - number=index + 1, + suffix=str(index + 1), verbosity=verbosity, keepdb=keepdb, ) @@ -292,7 +292,7 @@ def teardown_databases(old_config, verbosity, parallel=0, keepdb=False): if parallel > 1: for index in range(parallel): connection.creation.destroy_test_db( - number=index + 1, + suffix=str(index + 1), verbosity=verbosity, keepdb=keepdb, ) diff --git a/docs/releases/2.0.txt b/docs/releases/2.0.txt index fdb1d809627..a0d59995473 100644 --- a/docs/releases/2.0.txt +++ b/docs/releases/2.0.txt @@ -404,6 +404,12 @@ backends. :class:`~django.db.models.functions.Cast` function for a ``CharField`` if the ``max_length`` argument isn't provided. +* The first argument of ``DatabaseCreation._clone_test_db()`` and + ``get_test_db_clone_settings()`` is now ``suffix`` rather + than ``number`` (in case you want to rename the signatures in your backend + for consistency). ``django.test`` also now passes those values as strings + rather than as integers. + Dropped support for Oracle 11.2 -------------------------------