From 22e1dda8989e57d3fcbc4cac79d59065dbc6e4a9 Mon Sep 17 00:00:00 2001 From: Carlos Sousa Date: Mon, 25 Sep 2023 12:20:39 -0300 Subject: [PATCH] Update AsyncSession, replace get call by get_one, remove casting and null check --- lib/sqlalchemy/ext/asyncio/session.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/sqlalchemy/ext/asyncio/session.py b/lib/sqlalchemy/ext/asyncio/session.py index 14e5a484e6..5072e1f850 100644 --- a/lib/sqlalchemy/ext/asyncio/session.py +++ b/lib/sqlalchemy/ext/asyncio/session.py @@ -625,14 +625,14 @@ class AsyncSession(ReversibleProxy[Session]): execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT, ) -> _O: """Return an instance based on the given primary key identifier, - or raise an exception. + or raise an exception. - Raises ``sqlalchemy.orm.exc.NoResultFound`` if the query selects - no rows. + Raises ``sqlalchemy.orm.exc.NoResultFound`` if the query selects + no rows. """ result_obj = await greenlet_spawn( - cast("Callable[..., _O]", self.sync_session.get), + self.sync_session.get_one, entity, ident, options=options, @@ -640,12 +640,6 @@ class AsyncSession(ReversibleProxy[Session]): with_for_update=with_for_update, identity_token=identity_token, ) - - if result_obj is None: - raise async_exc.NoResultFound( - "No row was found when one was required" - ) - return result_obj @overload -- 2.47.3