Skip to content

Commit 3976537

Browse files
committed
Remove async_fallback mode
Removed the async_fallback mode and await_fallback function. Replace get_event_loop with Runner. Removed the internal function ``await_fallback()``. Renamed the internal function ``await_only()`` to ``await_()``. Change-Id: Ib43829be6ebdb59b6c4447f5a15b5d2b81403fa9
1 parent b12b7b1 commit 3976537

31 files changed

Lines changed: 263 additions & 533 deletions

README.unittests.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,10 @@ a pre-set URL. These can be seen using --dbs::
8383
$ pytest --dbs
8484
Available --db options (use --dburi to override)
8585
aiomysql mysql+aiomysql://scott:tiger@127.0.0.1:3306/test?charset=utf8mb4
86-
aiomysql_fallback mysql+aiomysql://scott:tiger@127.0.0.1:3306/test?charset=utf8mb4&async_fallback=true
8786
aiosqlite sqlite+aiosqlite:///:memory:
8887
aiosqlite_file sqlite+aiosqlite:///async_querytest.db
8988
asyncmy mysql+asyncmy://scott:tiger@127.0.0.1:3306/test?charset=utf8mb4
90-
asyncmy_fallback mysql+asyncmy://scott:tiger@127.0.0.1:3306/test?charset=utf8mb4&async_fallback=true
9189
asyncpg postgresql+asyncpg://scott:tiger@127.0.0.1:5432/test
92-
asyncpg_fallback postgresql+asyncpg://scott:tiger@127.0.0.1:5432/test?async_fallback=true
9390
default sqlite:///:memory:
9491
docker_mssql mssql+pymssql://scott:tiger^5HHH@127.0.0.1:1433/test
9592
mariadb mariadb+mysqldb://scott:tiger@127.0.0.1:3306/test
@@ -105,7 +102,6 @@ a pre-set URL. These can be seen using --dbs::
105102
psycopg postgresql+psycopg://scott:tiger@127.0.0.1:5432/test
106103
psycopg2 postgresql+psycopg2://scott:tiger@127.0.0.1:5432/test
107104
psycopg_async postgresql+psycopg_async://scott:tiger@127.0.0.1:5432/test
108-
psycopg_async_fallback postgresql+psycopg_async://scott:tiger@127.0.0.1:5432/test?async_fallback=true
109105
pymysql mysql+pymysql://scott:tiger@127.0.0.1:3306/test?charset=utf8mb4
110106
pysqlcipher_file sqlite+pysqlcipher://:test@/querytest.db.enc
111107
sqlite sqlite:///:memory:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. change::
2+
:tags: change, asyncio
3+
4+
Removed the compatibility ``async_fallback`` mode for async dialects,
5+
since it's no longer used by SQLAlchemy tests.
6+
Also removed the internal function ``await_fallback()`` and renamed
7+
the internal function ``await_only()`` to ``await_()``.
8+
No change is expected to user code.

lib/sqlalchemy/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@
4747
from .inspection import inspect as inspect
4848
from .pool import AssertionPool as AssertionPool
4949
from .pool import AsyncAdaptedQueuePool as AsyncAdaptedQueuePool
50-
from .pool import (
51-
FallbackAsyncAdaptedQueuePool as FallbackAsyncAdaptedQueuePool,
52-
)
5350
from .pool import NullPool as NullPool
5451
from .pool import Pool as Pool
5552
from .pool import PoolProxiedConnection as PoolProxiedConnection

lib/sqlalchemy/connectors/aioodbc.py

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@
1313
from .asyncio import AsyncAdapt_dbapi_connection
1414
from .asyncio import AsyncAdapt_dbapi_cursor
1515
from .asyncio import AsyncAdapt_dbapi_ss_cursor
16-
from .asyncio import AsyncAdaptFallback_dbapi_connection
1716
from .pyodbc import PyODBCConnector
18-
from .. import pool
19-
from .. import util
20-
from ..util.concurrency import await_fallback
21-
from ..util.concurrency import await_only
17+
from ..util.concurrency import await_
2218

2319
if TYPE_CHECKING:
2420
from ..engine.interfaces import ConnectArgsType
@@ -33,7 +29,7 @@ def setinputsizes(self, *inputsizes):
3329
return self._cursor._impl.setinputsizes(*inputsizes)
3430

3531
# how it's supposed to work
36-
# return self.await_(self._cursor.setinputsizes(*inputsizes))
32+
# return await_(self._cursor.setinputsizes(*inputsizes))
3733

3834

3935
class AsyncAdapt_aioodbc_ss_cursor(
@@ -59,7 +55,7 @@ def autocommit(self, value):
5955
self._connection._conn.autocommit = value
6056

6157
def ping(self, reconnect):
62-
return self.await_(self._connection.ping(reconnect))
58+
return await_(self._connection.ping(reconnect))
6359

6460
def add_output_converter(self, *arg, **kw):
6561
self._connection.add_output_converter(*arg, **kw)
@@ -96,12 +92,6 @@ def close(self):
9692
super().close()
9793

9894

99-
class AsyncAdaptFallback_aioodbc_connection(
100-
AsyncAdaptFallback_dbapi_connection, AsyncAdapt_aioodbc_connection
101-
):
102-
__slots__ = ()
103-
104-
10595
class AsyncAdapt_aioodbc_dbapi:
10696
def __init__(self, aioodbc, pyodbc):
10797
self.aioodbc = aioodbc
@@ -136,19 +126,12 @@ def _init_dbapi_attributes(self):
136126
setattr(self, name, getattr(self.pyodbc, name))
137127

138128
def connect(self, *arg, **kw):
139-
async_fallback = kw.pop("async_fallback", False)
140129
creator_fn = kw.pop("async_creator_fn", self.aioodbc.connect)
141130

142-
if util.asbool(async_fallback):
143-
return AsyncAdaptFallback_aioodbc_connection(
144-
self,
145-
await_fallback(creator_fn(*arg, **kw)),
146-
)
147-
else:
148-
return AsyncAdapt_aioodbc_connection(
149-
self,
150-
await_only(creator_fn(*arg, **kw)),
151-
)
131+
return AsyncAdapt_aioodbc_connection(
132+
self,
133+
await_(creator_fn(*arg, **kw)),
134+
)
152135

153136

154137
class aiodbcConnector(PyODBCConnector):
@@ -170,15 +153,6 @@ def create_connect_args(self, url: URL) -> ConnectArgsType:
170153

171154
return (), kw
172155

173-
@classmethod
174-
def get_pool_class(cls, url):
175-
async_fallback = url.query.get("async_fallback", False)
176-
177-
if util.asbool(async_fallback):
178-
return pool.FallbackAsyncAdaptedQueuePool
179-
else:
180-
return pool.AsyncAdaptedQueuePool
181-
182156
def _do_isolation_level(self, connection, autocommit, isolation_level):
183157
connection.set_autocommit(autocommit)
184158
connection.set_isolation_level(isolation_level)

lib/sqlalchemy/connectors/asyncio.py

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
from ..engine.interfaces import _DBAPICursorDescription
2626
from ..engine.interfaces import _DBAPIMultiExecuteParams
2727
from ..engine.interfaces import _DBAPISingleExecuteParams
28-
from ..util.concurrency import await_fallback
29-
from ..util.concurrency import await_only
28+
from ..util.concurrency import await_
3029
from ..util.typing import Self
3130

3231

@@ -121,7 +120,6 @@ class AsyncAdapt_dbapi_cursor:
121120
__slots__ = (
122121
"_adapt_connection",
123122
"_connection",
124-
"await_",
125123
"_cursor",
126124
"_rows",
127125
)
@@ -134,12 +132,11 @@ class AsyncAdapt_dbapi_cursor:
134132
def __init__(self, adapt_connection: AsyncAdapt_dbapi_connection):
135133
self._adapt_connection = adapt_connection
136134
self._connection = adapt_connection._connection
137-
self.await_ = adapt_connection.await_
138135

139136
cursor = self._make_new_cursor(self._connection)
140137

141138
try:
142-
self._cursor = self.await_(cursor.__aenter__())
139+
self._cursor = await_(cursor.__aenter__())
143140
except Exception as error:
144141
self._adapt_connection._handle_exception(error)
145142

@@ -181,7 +178,7 @@ def execute(
181178
parameters: Optional[_DBAPISingleExecuteParams] = None,
182179
) -> Any:
183180
try:
184-
return self.await_(self._execute_async(operation, parameters))
181+
return await_(self._execute_async(operation, parameters))
185182
except Exception as error:
186183
self._adapt_connection._handle_exception(error)
187184

@@ -191,7 +188,7 @@ def executemany(
191188
seq_of_parameters: _DBAPIMultiExecuteParams,
192189
) -> Any:
193190
try:
194-
return self.await_(
191+
return await_(
195192
self._executemany_async(operation, seq_of_parameters)
196193
)
197194
except Exception as error:
@@ -223,18 +220,16 @@ async def _executemany_async(
223220
return await self._cursor.executemany(operation, seq_of_parameters)
224221

225222
def nextset(self) -> None:
226-
self.await_(self._cursor.nextset())
223+
await_(self._cursor.nextset())
227224
if self._cursor.description and not self.server_side:
228-
self._rows = collections.deque(
229-
self.await_(self._cursor.fetchall())
230-
)
225+
self._rows = collections.deque(await_(self._cursor.fetchall()))
231226

232227
def setinputsizes(self, *inputsizes: Any) -> None:
233228
# NOTE: this is overrridden in aioodbc due to
234229
# see https://github.com/aio-libs/aioodbc/issues/451
235230
# right now
236231

237-
return self.await_(self._cursor.setinputsizes(*inputsizes))
232+
return await_(self._cursor.setinputsizes(*inputsizes))
238233

239234
def __enter__(self) -> Self:
240235
return self
@@ -273,24 +268,23 @@ class AsyncAdapt_dbapi_ss_cursor(AsyncAdapt_dbapi_cursor):
273268

274269
def close(self) -> None:
275270
if self._cursor is not None:
276-
self.await_(self._cursor.close())
271+
await_(self._cursor.close())
277272
self._cursor = None # type: ignore
278273

279274
def fetchone(self) -> Optional[Any]:
280-
return self.await_(self._cursor.fetchone())
275+
return await_(self._cursor.fetchone())
281276

282277
def fetchmany(self, size: Optional[int] = None) -> Any:
283-
return self.await_(self._cursor.fetchmany(size=size))
278+
return await_(self._cursor.fetchmany(size=size))
284279

285280
def fetchall(self) -> Sequence[Any]:
286-
return self.await_(self._cursor.fetchall())
281+
return await_(self._cursor.fetchall())
287282

288283

289284
class AsyncAdapt_dbapi_connection(AdaptedConnection):
290285
_cursor_cls = AsyncAdapt_dbapi_cursor
291286
_ss_cursor_cls = AsyncAdapt_dbapi_ss_cursor
292287

293-
await_ = staticmethod(await_only)
294288
__slots__ = ("dbapi", "_execute_mutex")
295289

296290
_connection: AsyncIODBAPIConnection
@@ -323,21 +317,15 @@ def _handle_exception(self, error: Exception) -> NoReturn:
323317

324318
def rollback(self) -> None:
325319
try:
326-
self.await_(self._connection.rollback())
320+
await_(self._connection.rollback())
327321
except Exception as error:
328322
self._handle_exception(error)
329323

330324
def commit(self) -> None:
331325
try:
332-
self.await_(self._connection.commit())
326+
await_(self._connection.commit())
333327
except Exception as error:
334328
self._handle_exception(error)
335329

336330
def close(self) -> None:
337-
self.await_(self._connection.close())
338-
339-
340-
class AsyncAdaptFallback_dbapi_connection(AsyncAdapt_dbapi_connection):
341-
__slots__ = ()
342-
343-
await_ = staticmethod(await_fallback)
331+
await_(self._connection.close())

lib/sqlalchemy/dialects/mysql/aiomysql.py

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,10 @@
2828
2929
""" # noqa
3030
from .pymysql import MySQLDialect_pymysql
31-
from ... import pool
32-
from ... import util
3331
from ...connectors.asyncio import AsyncAdapt_dbapi_connection
3432
from ...connectors.asyncio import AsyncAdapt_dbapi_cursor
3533
from ...connectors.asyncio import AsyncAdapt_dbapi_ss_cursor
36-
from ...connectors.asyncio import AsyncAdaptFallback_dbapi_connection
37-
from ...util.concurrency import await_fallback
38-
from ...util.concurrency import await_only
34+
from ...util.concurrency import await_
3935

4036

4137
class AsyncAdapt_aiomysql_cursor(AsyncAdapt_dbapi_cursor):
@@ -64,25 +60,19 @@ class AsyncAdapt_aiomysql_connection(AsyncAdapt_dbapi_connection):
6460

6561
def ping(self, reconnect):
6662
assert not reconnect
67-
return self.await_(self._connection.ping(reconnect))
63+
return await_(self._connection.ping(reconnect))
6864

6965
def character_set_name(self):
7066
return self._connection.character_set_name()
7167

7268
def autocommit(self, value):
73-
self.await_(self._connection.autocommit(value))
69+
await_(self._connection.autocommit(value))
7470

7571
def close(self):
7672
# it's not awaitable.
7773
self._connection.close()
7874

7975

80-
class AsyncAdaptFallback_aiomysql_connection(
81-
AsyncAdaptFallback_dbapi_connection, AsyncAdapt_aiomysql_connection
82-
):
83-
__slots__ = ()
84-
85-
8676
class AsyncAdapt_aiomysql_dbapi:
8777
def __init__(self, aiomysql, pymysql):
8878
self.aiomysql = aiomysql
@@ -118,19 +108,12 @@ def _init_dbapi_attributes(self):
118108
setattr(self, name, getattr(self.pymysql, name))
119109

120110
def connect(self, *arg, **kw):
121-
async_fallback = kw.pop("async_fallback", False)
122111
creator_fn = kw.pop("async_creator_fn", self.aiomysql.connect)
123112

124-
if util.asbool(async_fallback):
125-
return AsyncAdaptFallback_aiomysql_connection(
126-
self,
127-
await_fallback(creator_fn(*arg, **kw)),
128-
)
129-
else:
130-
return AsyncAdapt_aiomysql_connection(
131-
self,
132-
await_only(creator_fn(*arg, **kw)),
133-
)
113+
return AsyncAdapt_aiomysql_connection(
114+
self,
115+
await_(creator_fn(*arg, **kw)),
116+
)
134117

135118
def _init_cursors_subclasses(self):
136119
# suppress unconditional warning emitted by aiomysql
@@ -160,15 +143,6 @@ def import_dbapi(cls):
160143
__import__("aiomysql"), __import__("pymysql")
161144
)
162145

163-
@classmethod
164-
def get_pool_class(cls, url):
165-
async_fallback = url.query.get("async_fallback", False)
166-
167-
if util.asbool(async_fallback):
168-
return pool.FallbackAsyncAdaptedQueuePool
169-
else:
170-
return pool.AsyncAdaptedQueuePool
171-
172146
def create_connect_args(self, url):
173147
return super().create_connect_args(
174148
url, _translate_args=dict(username="user", database="db")

0 commit comments

Comments
 (0)