]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
use ensure_closed() for async close, close() for terminate
authorGord Thompson <gord@gordthompson.com>
Sun, 14 Jan 2024 16:49:11 +0000 (09:49 -0700)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 17 Jan 2024 15:33:35 +0000 (10:33 -0500)
Fixed issue in asyncio dialects asyncmy and aiomysql, where their
``.close()`` method is apparently not a graceful close.  replace with
non-standard ``.ensure_closed()`` method that's awaitable and move
``.close()`` to the so-called "terminate" case.

Fixes: #10893
Change-Id: I33d871e67854d85f770c46f699e41a6e73b6fbe0

doc/build/changelog/unreleased_20/10893.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/mysql/aiomysql.py
lib/sqlalchemy/dialects/mysql/asyncmy.py

diff --git a/doc/build/changelog/unreleased_20/10893.rst b/doc/build/changelog/unreleased_20/10893.rst
new file mode 100644 (file)
index 0000000..63507f3
--- /dev/null
@@ -0,0 +1,8 @@
+.. change::
+    :tags: bug, mysql
+    :tickets: 10893
+
+    Fixed issue in asyncio dialects asyncmy and aiomysql, where their
+    ``.close()`` method is apparently not a graceful close.  replace with
+    non-standard ``.ensure_closed()`` method that's awaitable and move
+    ``.close()`` to the so-called "terminate" case.
index 840a2bf5b49c9da2987d353ff1cd3207432f57f1..315ea6df95a577de3a935d4dbaecc1f874c4821d 100644 (file)
@@ -68,10 +68,13 @@ class AsyncAdapt_aiomysql_connection(AsyncAdapt_dbapi_connection):
     def autocommit(self, value):
         await_(self._connection.autocommit(value))
 
-    def close(self):
+    def terminate(self):
         # it's not awaitable.
         self._connection.close()
 
+    def close(self) -> None:
+        await_(self._connection.ensure_closed())
+
 
 class AsyncAdapt_aiomysql_dbapi:
     def __init__(self, aiomysql, pymysql):
@@ -136,6 +139,7 @@ class MySQLDialect_aiomysql(MySQLDialect_pymysql):
     _sscursor = AsyncAdapt_aiomysql_ss_cursor
 
     is_async = True
+    has_terminate = True
 
     @classmethod
     def import_dbapi(cls):
@@ -143,6 +147,9 @@ class MySQLDialect_aiomysql(MySQLDialect_pymysql):
             __import__("aiomysql"), __import__("pymysql")
         )
 
+    def do_terminate(self, dbapi_connection) -> None:
+        dbapi_connection.terminate()
+
     def create_connect_args(self, url):
         return super().create_connect_args(
             url, _translate_args=dict(username="user", database="db")
index 802546fb73c51fca19208b0155350c9de9470577..5fc36044dc86a1ccf6561c3f6776cc2bbc9de4a5 100644 (file)
@@ -81,10 +81,13 @@ class AsyncAdapt_asyncmy_connection(AsyncAdapt_dbapi_connection):
     def autocommit(self, value):
         await_(self._connection.autocommit(value))
 
-    def close(self):
+    def terminate(self):
         # it's not awaitable.
         self._connection.close()
 
+    def close(self) -> None:
+        await_(self._connection.ensure_closed())
+
 
 def _Binary(x):
     """Return x as a binary type."""
@@ -137,11 +140,15 @@ class MySQLDialect_asyncmy(MySQLDialect_pymysql):
     _sscursor = AsyncAdapt_asyncmy_ss_cursor
 
     is_async = True
+    has_terminate = True
 
     @classmethod
     def import_dbapi(cls):
         return AsyncAdapt_asyncmy_dbapi(__import__("asyncmy"))
 
+    def do_terminate(self, dbapi_connection) -> None:
+        dbapi_connection.terminate()
+
     def create_connect_args(self, url):
         return super().create_connect_args(
             url, _translate_args=dict(username="user", database="db")