Skip to content

Commit

Permalink
fix: use the simple query protocol to execute BEGIN/COMMIT out of pip…
Browse files Browse the repository at this point in the history
…eline

We started using the extended protocol in e507918 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.
  • Loading branch information
dvarrazzo committed May 14, 2024
1 parent 9045f18 commit a25378a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 11 additions & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------

Expand Down
8 changes: 7 additions & 1 deletion psycopg/psycopg/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,13 @@ def _exec_command(
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:
Expand Down

0 comments on commit a25378a

Please sign in to comment.