From 53aee470d5b35e2708864d5221d2b5655e10c091 Mon Sep 17 00:00:00 2001 From: Scott Macpherson Date: Thu, 13 Apr 2023 21:07:32 +1000 Subject: Fixed #34486 -- Fixed DatabaseOperations.compose_sql() crash with no existing database connection on PostgreSQL. Regression in 09ffc5c1212d4ced58b708cbbf3dfbfb77b782ca. --- django/db/backends/postgresql/psycopg_any.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'django') diff --git a/django/db/backends/postgresql/psycopg_any.py b/django/db/backends/postgresql/psycopg_any.py index 579104dead..1fe6b15caf 100644 --- a/django/db/backends/postgresql/psycopg_any.py +++ b/django/db/backends/postgresql/psycopg_any.py @@ -18,7 +18,8 @@ try: TSTZRANGE_OID = types["tstzrange"].oid def mogrify(sql, params, connection): - return ClientCursor(connection.connection).mogrify(sql, params) + with connection.cursor() as cursor: + return ClientCursor(cursor.connection).mogrify(sql, params) # Adapters. class BaseTzLoader(TimestamptzLoader): -- cgit v1.2.1