summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/_psycopg_common.py27
-rw-r--r--lib/sqlalchemy/dialects/postgresql/asyncpg.py11
2 files changed, 13 insertions, 25 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/_psycopg_common.py b/lib/sqlalchemy/dialects/postgresql/_psycopg_common.py
index d9ddefd38..739cbc5a9 100644
--- a/lib/sqlalchemy/dialects/postgresql/_psycopg_common.py
+++ b/lib/sqlalchemy/dialects/postgresql/_psycopg_common.py
@@ -178,20 +178,15 @@ class _PGDialect_common_psycopg(PGDialect):
def do_ping(self, dbapi_connection):
cursor = None
before_autocommit = dbapi_connection.autocommit
+
+ if not before_autocommit:
+ dbapi_connection.autocommit = True
+ cursor = dbapi_connection.cursor()
try:
- 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 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
- else:
- raise
- else:
- return True
+ cursor.execute(self._dialect_specific_select_one)
+ finally:
+ cursor.close()
+ if not before_autocommit and not dbapi_connection.closed:
+ dbapi_connection.autocommit = before_autocommit
+
+ return True
diff --git a/lib/sqlalchemy/dialects/postgresql/asyncpg.py b/lib/sqlalchemy/dialects/postgresql/asyncpg.py
index e00584503..2acc5fea3 100644
--- a/lib/sqlalchemy/dialects/postgresql/asyncpg.py
+++ b/lib/sqlalchemy/dialects/postgresql/asyncpg.py
@@ -992,15 +992,8 @@ class PGDialect_asyncpg(PGDialect):
return ([], opts)
def do_ping(self, dbapi_connection):
- try:
- dbapi_connection.ping()
- except self.dbapi.Error as err:
- if self.is_disconnect(err, dbapi_connection, None):
- return False
- else:
- raise
- else:
- return True
+ dbapi_connection.ping()
+ return True
@classmethod
def get_pool_class(cls, url):