]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Another Variant for detecting if a connection is closed
authorDirk Mueller <dmueller@suse.com>
Thu, 8 May 2014 15:07:44 +0000 (17:07 +0200)
committerDirk Mueller <dmueller@suse.com>
Sun, 11 May 2014 16:15:16 +0000 (18:15 +0200)
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".

lib/sqlalchemy/dialects/postgresql/psycopg2.py

index c4f7c032dc9fc1ad4cc0cdc2713321b6de91f955..5acba8abacd026fdc7a694b39e3a32d036998742 100644 (file)
@@ -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',