Deprecate the async_fallback mode and await_fallback function.
Additionally, this commit modifies the use of athrow
to no longer use the "util" compat function which is removed;
this has since been determined that it's not needed.
Change-Id: I37e37400b6954f5ac7c957790932838862930453
--- /dev/null
+.. change::
+ :tags: change, asyncio
+
+ The ``async_fallback`` dialect argument is now deprecated, and will be
+ removed in SQLAlchemy 2.1. This flag has not been used for SQLAlchemy's
+ test suite for some time. asyncio dialects can still run in a synchronous
+ style by running code within a greenlet using :func:`_util.greenlet_spawn`.
def get_select_precolumns(self, select, **kw):
"""Add special MySQL keywords in place of DISTINCT.
- .. deprecated:: 1.4 This usage is deprecated.
+ .. deprecated:: 1.4 This usage is deprecated.
:meth:`_expression.Select.prefix_with` should be used for special
keywords at the start of a SELECT.
from sqlalchemy.ext.asyncio import create_async_engine
engine = create_async_engine("postgresql+asyncpg://user:pass@hostname/dbname")
-The dialect can also be run as a "synchronous" dialect within the
-:func:`_sa.create_engine` function, which will pass "await" calls into
-an ad-hoc event loop. This mode of operation is of **limited use**
-and is for special testing scenarios only. The mode can be enabled by
-adding the SQLAlchemy-specific flag ``async_fallback`` to the URL
-in conjunction with :func:`_sa.create_engine`::
-
- # for testing purposes only; do not use in production!
- engine = create_engine("postgresql+asyncpg://user:pass@hostname/dbname?async_fallback=true")
-
-
.. versionadded:: 1.4
.. note::
# assemble connection arguments
(cargs_tup, cparams) = dialect.create_connect_args(u)
cparams.update(pop_kwarg("connect_args", {}))
+
+ if "async_fallback" in cparams and util.asbool(cparams["async_fallback"]):
+ util.warn_deprecated(
+ "The async_fallback dialect argument is deprecated and will be "
+ "removed in SQLAlchemy 2.1.",
+ "2.0",
+ )
+
cargs = list(cargs_tup) # allow mutability
# look for existing pool or create
# tell if we get the same exception back
value = typ()
try:
- await util.athrow(self.gen, typ, value, traceback)
+ await self.gen.athrow(value)
except StopAsyncIteration as exc:
# Suppress StopIteration *unless* it's the same exception that
# was passed to throw(). This prevents a StopIteration
from ._collections import WeakSequence as WeakSequence
from .compat import anext_ as anext_
from .compat import arm as arm
-from .compat import athrow as athrow
from .compat import b as b
from .compat import b64decode as b64decode
from .compat import b64encode as b64encode
:param awaitable: The coroutine to call.
+ .. deprecated:: 2.0.24 The ``await_fallback()`` function will be removed
+ in SQLAlchemy 2.1. Use :func:`_util.await_only` instead, running the
+ function / program / etc. within a top-level greenlet that is set up
+ using :func:`_util.greenlet_spawn`.
+
"""
# this is called in the context greenlet while running fn
import sys
import typing
from typing import Any
-from typing import AsyncGenerator
-from typing import Awaitable
from typing import Callable
from typing import Dict
from typing import Iterable
)
-if py312:
- # we are 95% certain this form of athrow works in former Python
- # versions, however we are unable to get confirmation;
- # see https://github.com/python/cpython/issues/105269 where have
- # been unable to get a straight answer so far
- def athrow( # noqa
- gen: AsyncGenerator[_T_co, Any], typ: Any, value: Any, traceback: Any
- ) -> Awaitable[_T_co]:
- return gen.athrow(value)
-
-else:
-
- def athrow( # noqa
- gen: AsyncGenerator[_T_co, Any], typ: Any, value: Any, traceback: Any
- ) -> Awaitable[_T_co]:
- return gen.athrow(typ, value, traceback)
-
-
if py39:
# python stubs don't have a public type for this. not worth
# making a protocol
)
# parameter has no effect
+
+
+class AsyncFallbackDeprecationTest(fixtures.TestBase):
+ __requires__ = ("greenlet",)
+
+ def test_async_fallback_deprecated(self):
+ with assertions.expect_deprecated(
+ "The async_fallback dialect argument is deprecated and will be "
+ "removed in SQLAlchemy 2.1.",
+ ):
+ create_engine(
+ "postgresql+asyncpg://?async_fallback=True", module=mock.Mock()
+ )
+
+ def test_async_fallback_false_is_ok(self):
+ create_engine(
+ "postgresql+asyncpg://?async_fallback=False", module=mock.Mock()
+ )