From 1564c362461f5252c7447972122e83d2aa6dc0f7 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 14 May 2024 13:18:40 +0200 Subject: [PATCH] fix: use the simple query protocol to execute BEGIN/COMMIT out of pipeline We started using the extended protocol in e5079184 to fix #350, but, probably to keep symmetry, we also changed the behaviour out of the pipeline. This turns out to be a problem for people connecting to the PgBouncer admin console. They can use the `ClientCursor`, which tries to use the simple protocol as much as it can, but they currently have to use autocommit. With this changeset autocommit shouldn't be needed anymore. See #808. --- docs/news.rst | 8 ++++++++ psycopg/psycopg/_connection_base.py | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/news.rst b/docs/news.rst index 6fee296f7..2e3c62d2c 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -46,6 +46,14 @@ Psycopg 3.2 (unreleased) .. __: https://numpy.org/doc/stable/reference/arrays.scalars.html#built-in-scalar-types +Psycopg 3.1.20 (unreleased) +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +- Use the simple query protocol to execute COMMIT/ROLLBACK when possible. + This should make querying the PgBouncer admin database easier + (:ticket:`#820`). + + Current release --------------- diff --git a/psycopg/psycopg/_connection_base.py b/psycopg/psycopg/_connection_base.py index 3c2ecf16e..dde4e1f7c 100644 --- a/psycopg/psycopg/_connection_base.py +++ b/psycopg/psycopg/_connection_base.py @@ -462,7 +462,13 @@ class BaseConnection(Generic[Row]): self._pipeline.result_queue.append(None) return None - self.pgconn.send_query_params(command, None, result_format=result_format) + # Unless needed, use the simple query protocol, e.g. to interact with + # pgbouncer. In pipeline mode we always use the advanced query protocol + # instead, see #350 + if result_format == TEXT: + self.pgconn.send_query(command) + else: + self.pgconn.send_query_params(command, None, result_format=result_format) result = (yield from generators.execute(self.pgconn))[-1] if result.status != COMMAND_OK and result.status != TUPLES_OK: -- 2.47.3