diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-04-23 13:07:36 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-04-23 13:07:36 -0400 |
| commit | 177ad548c458a9f1b8d43378fa8f16e349f80ac3 (patch) | |
| tree | ece5afbcc1f34401c4bcae535d079d760775af5e | |
| parent | 00c163bfb13d273e61dcb7ec78ac96338c916de7 (diff) | |
| download | sqlalchemy-177ad548c458a9f1b8d43378fa8f16e349f80ac3.tar.gz | |
- only search in the exception before the first newline, to avoid
false positives for SQL statements containing certain text
| -rw-r--r-- | doc/build/changelog/changelog_08.rst | 1 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/psycopg2.py | 5 |
2 files changed, 4 insertions, 2 deletions
diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index a3b7ffcb5..2a3d96ae0 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -15,6 +15,7 @@ the full exception hierarchy. Specifically the "closed the connection unexpectedly" message has now been seen in at least three different exception types. + Courtesy Eli Collins. .. change:: :tags: bug, sql, mysql diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index f5e122a1b..805fc72af 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -422,7 +422,7 @@ class PGDialect_psycopg2(PGDialect): def is_disconnect(self, e, connection, cursor): if isinstance(e, self.dbapi.Error): - str_e = str(e) + 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. @@ -439,7 +439,8 @@ class PGDialect_psycopg2(PGDialect): # be obsolete. It really says "losed", not "closed". 'losed the connection unexpectedly' ]: - if msg in str_e: + idx = str_e.find(msg) + if idx >= 0 and '"' not in str_e[:idx]: return True return False |
