summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2024-02-19 18:34:18 +0100
committerGitHub <noreply@github.com>2024-02-19 18:34:18 +0100
commit5f637a8a8d847ba02493c5ce6da55e378c3f588f (patch)
tree2f403bb0106a6e5c817d0558891a026a03f8b62b
parent9350308f374cad475312de3e648249d8b6f17341 (diff)
Fixed #35226 -- Reallowed executing queries for dynamically created connections.
Regression in 8fb0be3500cc7519a56985b1b6f415d75ac6fedb. Thanks Florian Apolloner for the report.
-rw-r--r--django/test/testcases.py2
-rw-r--r--tests/test_utils/tests.py10
2 files changed, 12 insertions, 0 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py
index 51b07ae50d..bf035bd531 100644
--- a/django/test/testcases.py
+++ b/django/test/testcases.py
@@ -280,6 +280,8 @@ class SimpleTestCase(unittest.TestCase):
self.connection is None
and self.alias not in cls.databases
and self.alias != NO_DB_ALIAS
+ # Dynamically created connections are always allowed.
+ and self.alias in connections
):
# Connection has not yet been established, but the alias is not allowed.
message = cls._disallowed_database_msg % {
diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py
index 7e9505f762..fab7f27aa1 100644
--- a/tests/test_utils/tests.py
+++ b/tests/test_utils/tests.py
@@ -2161,6 +2161,16 @@ class AllowedDatabaseQueriesTests(SimpleTestCase):
conn.close()
conn.dec_thread_sharing()
+ def test_allowed_database_copy_queries(self):
+ new_connection = connection.copy("dynamic_connection")
+ try:
+ with new_connection.cursor() as cursor:
+ sql = f"SELECT 1{new_connection.features.bare_select_suffix}"
+ cursor.execute(sql)
+ self.assertEqual(cursor.fetchone()[0], 1)
+ finally:
+ new_connection.close()
+
class DatabaseAliasTests(SimpleTestCase):
def setUp(self):