Skip to content

Commit

Permalink
Fixed #35226 -- Reallowed executing queries for dynamically created c…
Browse files Browse the repository at this point in the history
…onnections.

Regression in 8fb0be3.

Thanks Florian Apolloner for the report.
  • Loading branch information
felixxm authored Feb 19, 2024
1 parent 9350308 commit 5f637a8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions django/test/testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ def patched_ensure_connection(self, *args, **kwargs):
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 % {
Expand Down
10 changes: 10 additions & 0 deletions tests/test_utils/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2161,6 +2161,16 @@ def thread_func():
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):
Expand Down

0 comments on commit 5f637a8

Please sign in to comment.