Fixed #35226 -- Reallowed executing queries for dynamically created connections.

Regression in 8fb0be3500.

Thanks Florian Apolloner for the report.
This commit is contained in:
Mariusz Felisiak 2024-02-19 18:34:18 +01:00 committed by GitHub
parent 9350308f37
commit 5f637a8a8d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View File

@ -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 % {

View File

@ -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):