diff options
author | Dirk Mueller <dmueller@suse.com> | 2014-05-08 17:07:44 +0200 |
---|---|---|
committer | Dirk Mueller <dmueller@suse.com> | 2014-05-11 18:15:16 +0200 |
commit | 7ee8cd8f5ea609a8bef1153fdf85c15a2b5abcc3 (patch) | |
tree | ba5e4c7d851fccbda2a2a730e0bf69ca3c32d8db | |
parent | c8873b31f0c87ba0d1a7518b36af7151dec34be4 (diff) | |
download | sqlalchemy-pr/87.tar.gz |
Another Variant for detecting if a connection is closedpr/87
If there is a closed attribute on the connection and
it is true, return true. Implements a todo in the code
and helps in one specific disconnect case where it previously
did not match because the error message was "unknown error".
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/psycopg2.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index c4f7c032d..5acba8aba 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -489,12 +489,16 @@ class PGDialect_psycopg2(PGDialect): def is_disconnect(self, e, connection, cursor): if isinstance(e, self.dbapi.Error): + # Is the connection already marked as closed? + if getattr(connection, 'closed', False): + return True + str_e = str(e).partition("\n")[0] for msg in [ # these error messages from libpq: interfaces/libpq/fe-misc.c # and interfaces/libpq/fe-secure.c. # TODO: these are sent through gettext in libpq and we can't - # check within other locales - consider using connection.closed + # check within other locales 'terminating connection', 'closed the connection', 'connection not open', |