]> 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:35:20 +0000 (10:35 -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
(cherry picked from commit 4201b90210dcf60f9830df299be016dee315753b)

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 65482a76b278e7c754bc62ceadcc4ee8a85df646..405fa82c8a57613747f4e6a4937e4a20058d3d32 100644 (file)
@@ -202,10 +202,13 @@ class AsyncAdapt_aiomysql_connection(AdaptedConnection):
     def commit(self):
         self.await_(self._connection.commit())
 
-    def close(self):
+    def terminate(self):
         # it's not awaitable.
         self._connection.close()
 
+    def close(self) -> None:
+        self.await_(self._connection.ensure_closed())
+
 
 class AsyncAdaptFallback_aiomysql_connection(AsyncAdapt_aiomysql_connection):
     # TODO: base on connectors/asyncio.py
@@ -285,6 +288,7 @@ class MySQLDialect_aiomysql(MySQLDialect_pymysql):
     _sscursor = AsyncAdapt_aiomysql_ss_cursor
 
     is_async = True
+    has_terminate = True
 
     @classmethod
     def import_dbapi(cls):
@@ -301,6 +305,9 @@ class MySQLDialect_aiomysql(MySQLDialect_pymysql):
         else:
             return pool.AsyncAdaptedQueuePool
 
+    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 9928a879ec5bc812b8c923c7e6583d82152bd1f5..7360044d20b1886860bcf160c8f29c8e443b7573 100644 (file)
@@ -221,10 +221,13 @@ class AsyncAdapt_asyncmy_connection(AdaptedConnection):
     def commit(self):
         self.await_(self._connection.commit())
 
-    def close(self):
+    def terminate(self):
         # it's not awaitable.
         self._connection.close()
 
+    def close(self) -> None:
+        self.await_(self._connection.ensure_closed())
+
 
 class AsyncAdaptFallback_asyncmy_connection(AsyncAdapt_asyncmy_connection):
     __slots__ = ()
@@ -290,6 +293,7 @@ class MySQLDialect_asyncmy(MySQLDialect_pymysql):
     _sscursor = AsyncAdapt_asyncmy_ss_cursor
 
     is_async = True
+    has_terminate = True
 
     @classmethod
     def import_dbapi(cls):
@@ -304,6 +308,9 @@ class MySQLDialect_asyncmy(MySQLDialect_pymysql):
         else:
             return pool.AsyncAdaptedQueuePool
 
+    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")