--- /dev/null
+.. change::
+ :tags: bug, asyncio
+ :tickets: 6943
+
+ 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.
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,
"""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,
"""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,
return (
statement,
util.immutabledict(execution_options).union(
- dict(_sa_orm_update_options=update_options)
+ {"_sa_orm_update_options": update_options}
),
)
:param execution_options: optional dictionary of execution options,
which will be associated with the statement execution. This
dictionary can provide a subset of the options that are accepted
- by :meth:`_future.Connection.execution_options`, and may also
+ by :meth:`_engine.Connection.execution_options`, and may also
provide additional options understood only in an ORM context.
:param bind_arguments: dictionary of additional arguments to determine
class AsyncSessionQueryTest(AsyncFixture):
@async_test
- async def test_execute(self, async_session):
+ @testing.combinations(
+ {}, dict(execution_options={"logging_token": "test"}), argnames="kw"
+ )
+ async def test_execute(self, async_session, kw):
User = self.classes.User
stmt = (
.order_by(User.id)
)
- result = await async_session.execute(stmt)
+ result = await async_session.execute(stmt, **kw)
eq_(result.scalars().all(), self.static.user_address_result)
@async_test
@async_test
@testing.requires.independent_cursors
- async def test_stream_partitions(self, async_session):
+ @testing.combinations(
+ {}, dict(execution_options={"logging_token": "test"}), argnames="kw"
+ )
+ async def test_stream_partitions(self, async_session, kw):
User = self.classes.User
stmt = (
.order_by(User.id)
)
- result = await async_session.stream(stmt)
+ result = await async_session.stream(stmt, **kw)
assert_result = []
async for partition in result.scalars().partitions(3):