diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-02-13 11:17:09 -0500 |
---|---|---|
committer | mike bayer <mike_mp@zzzcomputing.com> | 2023-02-16 00:09:18 +0000 |
commit | 3fd081d070716fd5fc578555f945d503f9a91f91 (patch) | |
tree | 9becb3d07de9e69cc1681f19e7f11ab71268e506 /test/ext/asyncio/test_session_py3k.py | |
parent | 8855656626202e541bd2c95bc023e820a022322f (diff) | |
download | sqlalchemy-3fd081d070716fd5fc578555f945d503f9a91f91.tar.gz |
immediateload lazy relationships named in refresh.attribute_names
The :meth:`_orm.Session.refresh` method will now immediately load a
relationship-bound attribute that is explicitly named within the
:paramref:`_orm.Session.refresh.attribute_names` collection even if it is
currently linked to the "select" loader, which normally is a "lazy" loader
that does not fire off during a refresh. The "lazy loader" strategy will
now detect that the operation is specifically a user-initiated
:meth:`_orm.Session.refresh` operation which named this attribute
explicitly, and will then call upon the "immediateload" strategy to
actually emit SQL to load the attribute. This should be helpful in
particular for some asyncio situations where the loading of an unloaded
lazy-loaded attribute must be forced, without using the actual lazy-loading
attribute pattern not supported in asyncio.
Fixes: #9298
Change-Id: I9b50f339bdf06cdb2ec98f8e5efca2b690895dd7
Diffstat (limited to 'test/ext/asyncio/test_session_py3k.py')
-rw-r--r-- | test/ext/asyncio/test_session_py3k.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/test/ext/asyncio/test_session_py3k.py b/test/ext/asyncio/test_session_py3k.py index b34578dcc..36135a43d 100644 --- a/test/ext/asyncio/test_session_py3k.py +++ b/test/ext/asyncio/test_session_py3k.py @@ -164,6 +164,21 @@ class AsyncSessionQueryTest(AsyncFixture): is_(u3, None) @async_test + async def test_force_a_lazyload(self, async_session): + """test for #9298""" + + User = self.classes.User + + stmt = select(User).order_by(User.id) + + result = (await async_session.scalars(stmt)).all() + + for user_obj in result: + await async_session.refresh(user_obj, ["addresses"]) + + eq_(result, self.static.user_address_result) + + @async_test async def test_get_loader_options(self, async_session): User = self.classes.User |