From 42f29ae6525a5c5348c3ff2926607ec53eed5190 Mon Sep 17 00:00:00 2001 From: hbusul Date: Mon, 29 Mar 2021 11:42:33 -0400 Subject: [PATCH] accommodate new pg8000 disconnection exception Modified the ``is_disconnect()`` handler for the pg8000 dialect, which now accommodates for a new ``InterfaceError`` emitted by pg8000 1.19.0. Pull request courtesy Hamdi Burak Usul. Fixes: #6099 Closes: #6150 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/6150 Pull-request-sha: cd58836d3e19489d5203c02f7cc5f2f2d7c82a20 Change-Id: Ief942e53f6d90c48e8d77c70948fd46eb6c90dbd --- doc/build/changelog/unreleased_14/6099.rst | 8 ++++++++ lib/sqlalchemy/dialects/postgresql/pg8000.py | 7 +++++++ 2 files changed, 15 insertions(+) create mode 100644 doc/build/changelog/unreleased_14/6099.rst diff --git a/doc/build/changelog/unreleased_14/6099.rst b/doc/build/changelog/unreleased_14/6099.rst new file mode 100644 index 0000000000..5e715b9c57 --- /dev/null +++ b/doc/build/changelog/unreleased_14/6099.rst @@ -0,0 +1,8 @@ +.. change:: + :tags: bug, postgresql + :tickets: 6099 + + Modified the ``is_disconnect()`` handler for the pg8000 dialect, which now + accommodates for a new ``InterfaceError`` emitted by pg8000 1.19.0. Pull + request courtesy Hamdi Burak Usul. + diff --git a/lib/sqlalchemy/dialects/postgresql/pg8000.py b/lib/sqlalchemy/dialects/postgresql/pg8000.py index 6e73182727..cda0bc9415 100644 --- a/lib/sqlalchemy/dialects/postgresql/pg8000.py +++ b/lib/sqlalchemy/dialects/postgresql/pg8000.py @@ -328,6 +328,13 @@ class PGDialect_pg8000(PGDialect): return ([], opts) def is_disconnect(self, e, connection, cursor): + if isinstance( + e, self.dbapi.InterfaceError + ) and "network error" in str(e): + # new as of pg8000 1.19.0 for broken connections + return True + + # connection was closed normally return "connection is closed" in str(e) def set_isolation_level(self, connection, level): -- 2.47.2