]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- only search in the exception before the first newline, to avoid
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 23 Apr 2013 17:07:36 +0000 (13:07 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 23 Apr 2013 17:07:36 +0000 (13:07 -0400)
false positives for SQL statements containing certain text

doc/build/changelog/changelog_08.rst
lib/sqlalchemy/dialects/postgresql/psycopg2.py

index a3b7ffcb52fddb9975e56dc2c465bbe5ca2697d9..2a3d96ae01bfcc1955b9c9c5efee698807b09ca8 100644 (file)
@@ -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
index f5e122a1bf4be0bfe8c4c73b26f867b555bfc848..805fc72aff9d6bc628235f88c1946ee8b32cc2c3 100644 (file)
@@ -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