From 76d90152302461637cfecb6c0cac65a50975c570 Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Thu, 3 Dec 2020 23:53:47 +0100 Subject: Detect non compatible execution in async mode The SQLAlchemy async mode now detects and raises an informative error when an non asyncio compatible :term:`DBAPI` is used. Using a standard ``DBAPI`` with async SQLAlchemy will cause it to block like any sync call, interrupting the executing asyncio loop. Change-Id: I9aed87dc1b0df53e8cb2109495237038aa2cb2d4 --- lib/sqlalchemy/ext/asyncio/engine.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/sqlalchemy/ext/asyncio/engine.py') diff --git a/lib/sqlalchemy/ext/asyncio/engine.py b/lib/sqlalchemy/ext/asyncio/engine.py index 9e4851dfc..16edcc2b2 100644 --- a/lib/sqlalchemy/ext/asyncio/engine.py +++ b/lib/sqlalchemy/ext/asyncio/engine.py @@ -243,6 +243,7 @@ class AsyncConnection(StartableContext, AsyncConnectable): statement, parameters, execution_options, + _require_await=True, ) if result.context._is_server_side: raise async_exc.AsyncMethodRequired( @@ -272,6 +273,7 @@ class AsyncConnection(StartableContext, AsyncConnectable): util.EMPTY_DICT.merge_with( execution_options, {"stream_results": True} ), + _require_await=True, ) if not result.context._is_server_side: # TODO: real exception here @@ -322,6 +324,7 @@ class AsyncConnection(StartableContext, AsyncConnectable): statement, parameters, execution_options, + _require_await=True, ) if result.context._is_server_side: raise async_exc.AsyncMethodRequired( -- cgit v1.2.1