From 4fa017583ffc27f9204d6bf379dda854fb4fadbc Mon Sep 17 00:00:00 2001 From: "Francisco R. Del Roio" Date: Sat, 24 Feb 2024 22:49:04 -0300 Subject: [PATCH] Added fix for `AsyncConnection.run_sync`. --- lib/sqlalchemy/ext/asyncio/engine.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/sqlalchemy/ext/asyncio/engine.py b/lib/sqlalchemy/ext/asyncio/engine.py index 2b3a85465d..236cc1865a 100644 --- a/lib/sqlalchemy/ext/asyncio/engine.py +++ b/lib/sqlalchemy/ext/asyncio/engine.py @@ -21,6 +21,9 @@ from typing import TYPE_CHECKING from typing import TypeVar from typing import Union +from typing_extensions import Concatenate +from typing_extensions import ParamSpec + from . import exc as async_exc from .base import asyncstartablecontext from .base import GeneratorStartableContext @@ -63,6 +66,7 @@ if TYPE_CHECKING: from ...sql.base import Executable from ...sql.selectable import TypedReturnsRows +_P = ParamSpec("_P") _T = TypeVar("_T", bound=Any) _Ts = TypeVarTuple("_Ts") @@ -815,7 +819,10 @@ class AsyncConnection( yield result.scalars() async def run_sync( - self, fn: Callable[..., _T], *arg: Any, **kw: Any + self, + fn: Callable[Concatenate[Connection, _P], _T], + *arg: _P.args, + **kw: _P.kwargs, ) -> _T: """Invoke the given synchronous (i.e. not async) callable, passing a synchronous-style :class:`_engine.Connection` as the first @@ -879,7 +886,9 @@ class AsyncConnection( """ # noqa: E501 - return await greenlet_spawn(fn, self._proxied, *arg, **kw) + return await greenlet_spawn( + fn, self._proxied, *arg, _require_await=False, **kw + ) def __await__(self) -> Generator[Any, None, AsyncConnection]: return self.start().__await__() -- 2.47.2