From 177ad548c458a9f1b8d43378fa8f16e349f80ac3 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 23 Apr 2013 13:07:36 -0400 Subject: - only search in the exception before the first newline, to avoid false positives for SQL statements containing certain text --- lib/sqlalchemy/dialects/postgresql/psycopg2.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/dialects/postgresql/psycopg2.py') 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 -- cgit v1.2.1