]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix: use the simple query protocol to execute BEGIN/COMMIT out of pipeline
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 14 May 2024 11:18:40 +0000 (13:18 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 15 May 2024 16:34:16 +0000 (18:34 +0200)
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
psycopg/psycopg/connection.py

index af13ede4a0ad8d136dffcd3c2373c3c497915c7e..3e4161f75ab447ee99c2ca57b0cf2d812954eb8a 100644 (file)
@@ -7,6 +7,17 @@
 ``psycopg`` release notes
 =========================
 
+Future releases
+---------------
+
+Psycopg 3.1.20 (unreleased)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+- Use the simple query protocol to execute COMMIT/ROLLBACK when possible.
+  This should make easier to connect the PgBouncer admin database
+  (:ticket:`#820`).
+
+
 Current release
 ---------------
 
index e866368acba2c552e47bb9d61bc051bb8dc5c647..2724b1af0532f527d4ada31f71a030a7cd2f728f 100644 (file)
@@ -464,7 +464,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 execute(self.pgconn))[-1]
         if result.status != COMMAND_OK and result.status != TUPLES_OK: