From faa9ef2cff53bde291df5ac3b5c4ed8f665ecd8c Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 4 Feb 2022 09:04:49 -0500 Subject: ensure exception raised for all stream w/ sync result Fixed issue where the :meth:`_asyncio.AsyncSession.execute` method failed to raise an informative exception if the ``stream_results`` execution option were used, which is incompatible with a sync-style :class:`_result.Result` object. An exception is now raised in this scenario in the same way one is already raised when using ``stream_results`` in conjunction with the :meth:`_asyncio.AsyncConnection.execute` method. Additionally, for improved stability with state-sensitive dialects such as asyncmy, the cursor is now closed when this error condition is raised; previously with the asyncmy dialect, the connection would go into an invalid state with unconsumed server side results remaining. Fixes: #7667 Change-Id: I6eb7affe08584889b57423a90258295f8b7085dc --- lib/sqlalchemy/ext/asyncio/session.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/ext/asyncio/session.py') diff --git a/lib/sqlalchemy/ext/asyncio/session.py b/lib/sqlalchemy/ext/asyncio/session.py index 0840a0d7d..22de2cab1 100644 --- a/lib/sqlalchemy/ext/asyncio/session.py +++ b/lib/sqlalchemy/ext/asyncio/session.py @@ -8,6 +8,7 @@ from . import engine from . import result as _result from .base import ReversibleProxy from .base import StartableContext +from .result import _ensure_sync_result from ... import util from ...orm import object_session from ...orm import Session @@ -208,7 +209,7 @@ class AsyncSession(ReversibleProxy): else: execution_options = _EXECUTE_OPTIONS - return await greenlet_spawn( + result = await greenlet_spawn( self.sync_session.execute, statement, params=params, @@ -216,6 +217,7 @@ class AsyncSession(ReversibleProxy): bind_arguments=bind_arguments, **kw, ) + return await _ensure_sync_result(result, self.execute) async def scalar( self, -- cgit v1.2.1