diff options
author | Federico Caselli <cfederico87@gmail.com> | 2022-04-11 23:19:16 +0200 |
---|---|---|
committer | Federico Caselli <cfederico87@gmail.com> | 2022-04-13 22:29:55 +0200 |
commit | c154ed5e047113ce6763cc5a26741f6a5022eb1d (patch) | |
tree | c295a93f303e920b7c647f48fbe53de77146a4db /lib/sqlalchemy/dialects/postgresql/psycopg.py | |
parent | fd052732604a0d03167978215f0077e60b75851d (diff) | |
download | sqlalchemy-c154ed5e047113ce6763cc5a26741f6a5022eb1d.tar.gz |
Fix psycopg2 pre_ping with autocommit
Fixed an issue what would cause autocommit mode to be reset
when using pre_ping in conjunction engine level autocommit
on the psycopg2 driver.
Fixes: #7930
Change-Id: I4cccaf1b7f8cbacd853689458080784114fcc390
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/psycopg.py')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/psycopg.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg.py b/lib/sqlalchemy/dialects/postgresql/psycopg.py index 9207221df..b811d1cab 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg.py @@ -385,12 +385,14 @@ class PGDialect_psycopg(_PGDialect_common_psycopg): != self._psycopg_TransactionStatus.IDLE ): dbapi_conn.rollback() - before = dbapi_conn.autocommit + before_autocommit = dbapi_conn.autocommit try: - self._do_autocommit(dbapi_conn, True) + if not before_autocommit: + self._do_autocommit(dbapi_conn, True) dbapi_conn.execute(command) finally: - self._do_autocommit(dbapi_conn, before) + if not before_autocommit: + self._do_autocommit(dbapi_conn, before_autocommit) def do_rollback_twophase( self, connection, xid, is_prepared=True, recover=False |