diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-04-22 19:33:49 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-04-22 19:33:49 -0400 |
| commit | b6f04d928853df8cb575fba9ba87c07c66564cd6 (patch) | |
| tree | 5f3912e5802236a0f69aae742690c6f9f4c85ec4 /lib/sqlalchemy | |
| parent | 600b4bc1a2ac093af5797ecd8717bbc038f1e5c1 (diff) | |
| parent | 00c163bfb13d273e61dcb7ec78ac96338c916de7 (diff) | |
| download | sqlalchemy-b6f04d928853df8cb575fba9ba87c07c66564cd6.tar.gz | |
merge default
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/psycopg2.py | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index 1f118067f..f5e122a1b 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -421,23 +421,26 @@ class PGDialect_psycopg2(PGDialect): return ([], opts) def is_disconnect(self, e, connection, cursor): - if isinstance(e, self.dbapi.OperationalError): - # these error messages from libpq: interfaces/libpq/fe-misc.c. - # TODO: these are sent through gettext in libpq and we can't - # check within other locales - consider using connection.closed - return 'terminating connection' in str(e) or \ - 'closed the connection' in str(e) or \ - 'connection not open' in str(e) or \ - 'could not receive data from server' in str(e) - elif isinstance(e, self.dbapi.InterfaceError): - # psycopg2 client errors, psycopg2/conenction.h, psycopg2/cursor.h - return 'connection already closed' in str(e) or \ - 'cursor already closed' in str(e) - elif isinstance(e, self.dbapi.ProgrammingError): - # not sure where this path is originally from, it may - # be obsolete. It really says "losed", not "closed". - return "losed the connection unexpectedly" in str(e) - else: - return False + if isinstance(e, self.dbapi.Error): + str_e = str(e) + 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 + 'terminating connection', + 'closed the connection', + 'connection not open', + 'could not receive data from server', + # psycopg2 client errors, psycopg2/conenction.h, psycopg2/cursor.h + 'connection already closed', + 'cursor already closed', + # not sure where this path is originally from, it may + # be obsolete. It really says "losed", not "closed". + 'losed the connection unexpectedly' + ]: + if msg in str_e: + return True + return False dialect = PGDialect_psycopg2 |
