summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/_psycopg_common.py8
-rw-r--r--lib/sqlalchemy/dialects/postgresql/psycopg.py8
2 files changed, 10 insertions, 6 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/_psycopg_common.py b/lib/sqlalchemy/dialects/postgresql/_psycopg_common.py
index 7f936fefb..e7d5e77c3 100644
--- a/lib/sqlalchemy/dialects/postgresql/_psycopg_common.py
+++ b/lib/sqlalchemy/dialects/postgresql/_psycopg_common.py
@@ -170,15 +170,17 @@ class _PGDialect_common_psycopg(PGDialect):
def do_ping(self, dbapi_connection):
cursor = None
+ before_autocommit = dbapi_connection.autocommit
try:
- self._do_autocommit(dbapi_connection, True)
+ if not before_autocommit:
+ self._do_autocommit(dbapi_connection, True)
cursor = dbapi_connection.cursor()
try:
cursor.execute(self._dialect_specific_select_one)
finally:
cursor.close()
- if not dbapi_connection.closed:
- self._do_autocommit(dbapi_connection, False)
+ if not before_autocommit and not dbapi_connection.closed:
+ self._do_autocommit(dbapi_connection, before_autocommit)
except self.dbapi.Error as err:
if self.is_disconnect(err, dbapi_connection, cursor):
return False
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