summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext/asyncio/session.py
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2021-08-26 22:00:33 +0200
committerFederico Caselli <cfederico87@gmail.com>2021-08-26 22:00:58 +0200
commitf02349336fa4470dbb5ca8e4d16031b8aa86a74a (patch)
tree0cacf340d84e198e64b30ca14a015a4a4973caf5 /lib/sqlalchemy/ext/asyncio/session.py
parente2d9ef3fe6f7bd9b151caf71ae5eb7f15522ec8c (diff)
downloadsqlalchemy-f02349336fa4470dbb5ca8e4d16031b8aa86a74a.tar.gz
Handle mappings passed to ``execution_options``.
Fixed a bug in :meth:`_asyncio.AsyncSession.execute` and :meth:`_asyncio.AsyncSession.stream` that required ``execution_options`` to be an instance of ``immutabledict`` when defined. It now correctly accepts any mapping. Fixes: #6943 Change-Id: Ic09de480dc2da1b0bdce25acb60b8f01371971f9
Diffstat (limited to 'lib/sqlalchemy/ext/asyncio/session.py')
-rw-r--r--lib/sqlalchemy/ext/asyncio/session.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/sqlalchemy/ext/asyncio/session.py b/lib/sqlalchemy/ext/asyncio/session.py
index a10621eef..5c6e7f5a7 100644
--- a/lib/sqlalchemy/ext/asyncio/session.py
+++ b/lib/sqlalchemy/ext/asyncio/session.py
@@ -14,6 +14,9 @@ from ...orm import Session
from ...orm import state as _instance_state
from ...util.concurrency import greenlet_spawn
+_EXECUTE_OPTIONS = util.immutabledict({"prebuffer_rows": True})
+_STREAM_OPTIONS = util.immutabledict({"stream_results": True})
+
@util.create_proxy_methods(
Session,
@@ -140,7 +143,12 @@ class AsyncSession(ReversibleProxy):
"""Execute a statement and return a buffered
:class:`_engine.Result` object."""
- execution_options = execution_options.union({"prebuffer_rows": True})
+ if execution_options:
+ execution_options = util.immutabledict(execution_options).union(
+ _EXECUTE_OPTIONS
+ )
+ else:
+ execution_options = _EXECUTE_OPTIONS
return await greenlet_spawn(
self.sync_session.execute,
@@ -205,7 +213,12 @@ class AsyncSession(ReversibleProxy):
"""Execute a statement and return a streaming
:class:`_asyncio.AsyncResult` object."""
- execution_options = execution_options.union({"stream_results": True})
+ if execution_options:
+ execution_options = util.immutabledict(execution_options).union(
+ _STREAM_OPTIONS
+ )
+ else:
+ execution_options = _STREAM_OPTIONS
result = await greenlet_spawn(
self.sync_session.execute,