From 664c98f1f8c63a932a9c767a7364a6a1826799bb Mon Sep 17 00:00:00 2001 From: Farhaan Bukhsh Date: Wed, 20 Nov 2019 23:07:10 +0530 Subject: [PATCH] Fixed #30413 -- Fixed test database signature on SQLite when test database name is provided. Previously, the same signature was created for multiple in-memory databases on SQLite when they had tests databases names DATABASES['TEST']['NAME']. --- django/db/backends/sqlite3/creation.py | 2 ++ tests/backends/sqlite/test_creation.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/backends/sqlite/test_creation.py diff --git a/django/db/backends/sqlite3/creation.py b/django/db/backends/sqlite3/creation.py index d97052f52d..f3bb8dd3b2 100644 --- a/django/db/backends/sqlite3/creation.py +++ b/django/db/backends/sqlite3/creation.py @@ -98,4 +98,6 @@ class DatabaseCreation(BaseDatabaseCreation): sig = [self.connection.settings_dict['NAME']] if self.is_in_memory_db(test_database_name): sig.append(self.connection.alias) + else: + sig.append(test_database_name) return tuple(sig) diff --git a/tests/backends/sqlite/test_creation.py b/tests/backends/sqlite/test_creation.py new file mode 100644 index 0000000000..72d032440f --- /dev/null +++ b/tests/backends/sqlite/test_creation.py @@ -0,0 +1,18 @@ +import copy +import unittest + +from django.db import connection +from django.test import SimpleTestCase + + +@unittest.skipUnless(connection.vendor == 'sqlite', 'SQLite tests') +class TestDbSignatureTests(SimpleTestCase): + def test_custom_test_name(self): + saved_settings = copy.deepcopy(connection.settings_dict) + try: + connection.settings_dict['NAME'] = None + connection.settings_dict['TEST']['NAME'] = 'custom.sqlite.db' + signature = connection.creation.test_db_signature() + self.assertEqual(signature, (None, 'custom.sqlite.db')) + finally: + connection.settings_dict = saved_settings