From: Federico Caselli Date: Thu, 30 Sep 2021 21:26:33 +0000 (+0200) Subject: Document dynamic for asyncio X-Git-Tag: rel_1_4_26~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aba965ca12b215cb5936ad385396928ea418dcb9;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Document dynamic for asyncio Change-Id: Ieedc748587288c30630a2453f20eb72001cb78ab (cherry picked from commit aeb61f4bb7d0b6d3d550d0206046208d6d4d7e91) --- diff --git a/doc/build/orm/collections.rst b/doc/build/orm/collections.rst index e803fc7843..bc98b4b41d 100644 --- a/doc/build/orm/collections.rst +++ b/doc/build/orm/collections.rst @@ -37,6 +37,9 @@ Dynamic Relationship Loaders method of use. For relationships that shouldn't load, set :paramref:`_orm.relationship.lazy` to ``noload``. +.. note:: This loader is in the general case not compatible with the :ref:`asyncio_toplevel` extension. + It can be used with some limitations, as indicated in :ref:`Asyncio dynamic guidelines `. + A :func:`_orm.relationship` which corresponds to a large collection can be configured so that it returns a legacy :class:`_orm.Query` object when accessed, which allows filtering of the relationship on criteria. The class is diff --git a/doc/build/orm/extensions/asyncio.rst b/doc/build/orm/extensions/asyncio.rst index 9bc72d362c..fcaf104467 100644 --- a/doc/build/orm/extensions/asyncio.rst +++ b/doc/build/orm/extensions/asyncio.rst @@ -327,11 +327,21 @@ Other guidelines include: constructs as noted above. See :ref:`deferred` for background on deferred column loading. +.. _dynamic_asyncio: + * The "dynamic" relationship loader strategy described at - :ref:`dynamic_relationship` is not compatible with the asyncio approach and - cannot be used, unless invoked within the + :ref:`dynamic_relationship` is not compatible by default with the asyncio approach. + It can be used directly only if invoked within the :meth:`_asyncio.AsyncSession.run_sync` method described at - :ref:`session_run_sync`. + :ref:`session_run_sync`, or by using its ``.statement`` attribute + to obtain a normal select:: + + user = await session.get(User, 42) + addresses = (await session.scalars(user.addresses.statement)).all() + stmt = user.addresses.statement.where( + Address.email_address.startswith("patrick") + ) + addresses_filter = (await session.scalars(stmt)).all() .. _session_run_sync: