Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "rda_python_common"
version = "3.0.0"
version = "3.0.1"
authors = [
{ name="Zaihua Ji", email="zji@ucar.edu" },
]
Expand Down
8 changes: 6 additions & 2 deletions src/rda_python_common/PgDBI.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,12 @@ def starttran():
pgconnect(0, 0, False)
else:
try:
pgdb.isolation_level
except PgSQL.OperationalError as e:
# Liveness probe: psycopg2's isolation_level getter could raise on a
# dead connection, but psycopg3's is a cached attribute that never
# touches the server. A trivial round-trip detects a broken
# connection under either driver.
pgdb.cursor().execute("SELECT 1")
except PgSQL.Error as e:
pgconnect(0, 0, False)
if pgdb.closed:
pgconnect(0, 0, False)
Expand Down
14 changes: 11 additions & 3 deletions src/rda_python_common/pg_dbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,12 @@ def starttran(self):
self.pgconnect(0, 0, False)
else:
try:
self.pgdb.isolation_level
except PgSQL.OperationalError as e:
# Liveness probe: psycopg2's isolation_level getter could raise on a
# dead connection, but psycopg3's is a cached attribute that never
# touches the server. A trivial round-trip detects a broken
# connection under either driver.
self.pgdb.cursor().execute("SELECT 1")
except PgSQL.Error as e:
self.pgconnect(0, 0, False)
if self.pgdb.closed:
self.pgconnect(0, 0, False)
Expand Down Expand Up @@ -533,7 +537,11 @@ def try_add_table(self, dberror, logact):
dberror (str): Full database error string to inspect.
logact (int): Logging action flags forwarded to add_new_table().
"""
ms = re.match(r'^42P01 ERROR: relation "(.+)" does not exist', dberror)
# The caller (check_dberror) only invokes this after pgcode == '42P01', so
# match just the relation message. psycopg2's pgerror includes the
# 'ERROR: ' severity prefix while psycopg3's message_primary does not, so
# anchoring on that prefix only matched under psycopg2.
ms = re.search(r'relation "(.+)" does not exist', dberror)
if ms:
tname = ms.group(1)
self.add_new_table(tname, logact = logact)
Expand Down
Loading