]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
place asyncpg do_ping within a transaction if one not begun already
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 16 Aug 2023 19:38:51 +0000 (15:38 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 18 Aug 2023 15:27:33 +0000 (11:27 -0400)
commite5c881488e1f06f46ee3ddcfb513431efce3cd7b
treef4d5edd0acd1c56e2483143f355441cd5ede7eff
parente5a81c980b5c07f7d980b90149c6b18ea16f6f4b
place asyncpg do_ping within a transaction if one not begun already

Fixed regression which appeared in 2.0 due to :ticket:`8491` where the
revised "ping" used for PostgreSQL dialects when the
:paramref:`_sa.create_engine.pool_pre_ping` parameter is in use would
interfere with the use of asyncpg with PGBouncer "transaction" mode, as the
multiple PostgreSQL commands emitted by asnycpg could be broken out among
multiple connections leading to errors, due to the lack of any transaction
around this newly revised "ping".   The ping is now invoked within a
transaction, in the same way that is implicit with all other backends that
are based on the pep-249 DBAPI; this guarantees that the series of PG
commands sent by asyncpg for this command are invoked on the same backend
connection without it jumping to a different connection mid-command.  The
transaction is not used if the asyncpg dialect is used in "AUTOCOMMIT"
mode, which remains incompatible with pgbouncer transaction mode.

Fixes: #10226
Change-Id: I93156ad7c353a865d93e5296bd7bc137f0350f3c
doc/build/changelog/unreleased_20/10226.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/postgresql/asyncpg.py
test/dialect/postgresql/test_dialect.py