]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
include InterfaceError for mariadb disconnect check
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 14 Dec 2021 21:46:50 +0000 (16:46 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 16 Dec 2021 14:17:04 +0000 (09:17 -0500)
Corrected the error classes inspected for the "is_disconnect" check for the
``mariadbconnector`` dialect, which was failing for disconnects that
occurred due to common MySQL/MariaDB error codes such as 2006; the DBAPI
appears to currently use the ``mariadb.InterfaceError`` exception class for
disconnect errors such as error code 2006, which has been added to the list
of classes checked.

For the current "real reconnect test", shutting down the mariadb
connection from the client side produces
ProgrammingError("Connection isn't valid anymore") which we also
continue to intercept.

Fixes: #7457
Change-Id: I0b37cd7a73359a23ad756ff2af0a9333c841221b

doc/build/changelog/unreleased_14/7457.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/mysql/base.py

diff --git a/doc/build/changelog/unreleased_14/7457.rst b/doc/build/changelog/unreleased_14/7457.rst
new file mode 100644 (file)
index 0000000..b1942b0
--- /dev/null
@@ -0,0 +1,11 @@
+.. change::
+    :tags: bug, mariadb
+    :tickets: 7457
+
+    Corrected the error classes inspected for the "is_disconnect" check for the
+    ``mariadbconnector`` dialect, which was failing for disconnects that
+    occurred due to common MySQL/MariaDB error codes such as 2006; the DBAPI
+    appears to currently use the ``mariadb.InterfaceError`` exception class for
+    disconnect errors such as error code 2006, which has been added to the list
+    of classes checked.
+
index fef1ec81a5bc3d55a833bb5000b81f909e02e76f..fe0624d089301c95d4f4df32b7cdb0c6d4977dec 100644 (file)
@@ -2540,16 +2540,21 @@ class MySQLDialect(default.DefaultDialect):
 
     def is_disconnect(self, e, connection, cursor):
         if isinstance(
-            e, (self.dbapi.OperationalError, self.dbapi.ProgrammingError)
+            e,
+            (
+                self.dbapi.OperationalError,
+                self.dbapi.ProgrammingError,
+                self.dbapi.InterfaceError,
+            ),
+        ) and self._extract_error_code(e) in (
+            1927,
+            2006,
+            2013,
+            2014,
+            2045,
+            2055,
         ):
-            return self._extract_error_code(e) in (
-                1927,
-                2006,
-                2013,
-                2014,
-                2045,
-                2055,
-            )
+            return True
         elif isinstance(
             e, (self.dbapi.InterfaceError, self.dbapi.InternalError)
         ):