]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Include new MySQL error code 4031 for MySQL disconnect check 8037/head
authorvalievkarim <valievkarim@gmail.com>
Wed, 18 May 2022 15:54:57 +0000 (17:54 +0200)
committervalievkarim <valievkarim@gmail.com>
Wed, 18 May 2022 19:35:37 +0000 (22:35 +0300)
When using pool_pre_ping=True with MySQL version 8.0.28 and a stale
connection, SQLAlchemy raises the following error instead of
reconnecting:

MySQLdb._exceptions.OperationalError: (4031, 'The client was disconnected by the server because of inactivity. See wait_timeout and interactive_timeout for configuring this behavior.')

4031 (ER_CLIENT_INTERACTION_TIMEOUT) is a new error code added in
MySQL version 8.0.24:
https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html#error_er_client_interaction_timeout

This commit adds 4031 to the error codes list checked in MySQL dialect
"is_disconnect" check.

Fixes: #8036
doc/build/changelog/unreleased_14/8036.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/mysql/base.py
test/dialect/mysql/test_dialect.py

diff --git a/doc/build/changelog/unreleased_14/8036.rst b/doc/build/changelog/unreleased_14/8036.rst
new file mode 100644 (file)
index 0000000..c2b6163
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+    :tags: bug, mysql
+    :tickets: 8036
+
+    Fixed an issue in the mysql dialect when using the
+    :paramref:`.create_engine.pool_pre_ping` parameter with MySQL >=
+    8.0.24, an exception was raised instead of reconnecting
index 420fcfdfdbc80230baa44cc327ed46f20a825552..65de88cfe6df491fbf08ce12bc960961ec31f706 100644 (file)
@@ -2568,6 +2568,7 @@ class MySQLDialect(default.DefaultDialect):
             2014,
             2045,
             2055,
+            4031,
         ):
             return True
         elif isinstance(
index 4fa524a35c7bd94b5446f39412cf0ec592f5a453..d79f2629fad32d1c19dedb00ca9d1f9bd8ee6525 100644 (file)
@@ -199,6 +199,10 @@ class DialectTest(fixtures.TestBase):
         (2006, "foo", "OperationalError", "pymysql", True),
         (2007, "foo", "OperationalError", "mysqldb", False),
         (2007, "foo", "OperationalError", "pymysql", False),
+        (4031, "foo", "OperationalError", "mysqldb", True),
+        (4031, "foo", "OperationalError", "pymysql", True),
+        (4032, "foo", "OperationalError", "mysqldb", False),
+        (4032, "foo", "OperationalError", "pymysql", False),
     )
     def test_is_disconnect(
         self, arg0, message, exc_cls_name, dialect_name, is_disconnect