]> 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:37:43 +0000 (18:37 +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_base.py

index 6fee296f715857047ffa0ff6159c35f7a4121d3f..2e3c62d2c5d99693b2647d32e3c7a13a62a0ea33 100644 (file)
@@ -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
 ---------------
 
index 3c2ecf16e95eed6ae1e8f54d55233720697629c4..dde4e1f7c9542104f729dab42198da461cf6fdd1 100644 (file)
@@ -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: