summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql/operations.py
diff options
context:
space:
mode:
authorMichail Chatzis <michatzis@gmail.com>2024-02-02 14:38:30 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2024-03-06 11:24:58 +0100
commit4426b1a72dc289643e2ae8c190b8dc4b3a39daf7 (patch)
tree27760cd293ea4e6dbd5a8f05dc2a443abc499f13 /django/db/backends/postgresql/operations.py
parent177e6493961dfcdafb44e5b02894bf4201050910 (diff)
Fixed #35021 -- Fixed capturing queries when using client-side parameters binding with psycopg 3+.
Diffstat (limited to 'django/db/backends/postgresql/operations.py')
-rw-r--r--django/db/backends/postgresql/operations.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py
index 06981bc094..4e444d5f2b 100644
--- a/django/db/backends/postgresql/operations.py
+++ b/django/db/backends/postgresql/operations.py
@@ -296,9 +296,14 @@ class DatabaseOperations(BaseDatabaseOperations):
if is_psycopg3:
def last_executed_query(self, cursor, sql, params):
- try:
- return self.compose_sql(sql, params)
- except errors.DataError:
+ if self.connection.features.uses_server_side_binding:
+ try:
+ return self.compose_sql(sql, params)
+ except errors.DataError:
+ return None
+ else:
+ if cursor._query and cursor._query.query is not None:
+ return cursor._query.query.decode()
return None
else: