From 81539b6d84eb024d58f81b9d7d1885ed0f199357 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Wed, 9 Apr 2025 05:43:25 +0900 Subject: [PATCH] orm.exc.NoResultFound => exc.NoResultFound (#12509) * s/orm.exc.NoResultFound/exc.NoResultFound/ * use _exc (cherry picked from commit d5a913c8aefad763539f8fd88b99118bcabb19a2) --- lib/sqlalchemy/engine/result.py | 4 ++-- lib/sqlalchemy/ext/asyncio/scoping.py | 3 +-- lib/sqlalchemy/ext/asyncio/session.py | 3 +-- lib/sqlalchemy/orm/query.py | 11 +++++------ lib/sqlalchemy/orm/scoping.py | 3 +-- lib/sqlalchemy/orm/session.py | 3 +-- 6 files changed, 11 insertions(+), 16 deletions(-) diff --git a/lib/sqlalchemy/engine/result.py b/lib/sqlalchemy/engine/result.py index 3c81fc6052..ed099da05d 100644 --- a/lib/sqlalchemy/engine/result.py +++ b/lib/sqlalchemy/engine/result.py @@ -1489,8 +1489,8 @@ class Result(_WithKeys, ResultInternal[Row[_TP]]): def one(self) -> Row[_TP]: """Return exactly one row or raise an exception. - Raises :class:`.NoResultFound` if the result returns no - rows, or :class:`.MultipleResultsFound` if multiple rows + Raises :class:`_exc.NoResultFound` if the result returns no + rows, or :class:`_exc.MultipleResultsFound` if multiple rows would be returned. .. note:: This method returns one **row**, e.g. tuple, by default. diff --git a/lib/sqlalchemy/ext/asyncio/scoping.py b/lib/sqlalchemy/ext/asyncio/scoping.py index 7ecab37b40..d2a9a51b23 100644 --- a/lib/sqlalchemy/ext/asyncio/scoping.py +++ b/lib/sqlalchemy/ext/asyncio/scoping.py @@ -1175,8 +1175,7 @@ class async_scoped_session(Generic[_AS]): Proxied for the :class:`_asyncio.AsyncSession` class on behalf of the :class:`_asyncio.scoping.async_scoped_session` class. - Raises ``sqlalchemy.orm.exc.NoResultFound`` if the query selects - no rows. + Raises :class:`_exc.NoResultFound` if the query selects no rows. ..versionadded: 2.0.22 diff --git a/lib/sqlalchemy/ext/asyncio/session.py b/lib/sqlalchemy/ext/asyncio/session.py index 1b8c9695c7..68cbb59bfd 100644 --- a/lib/sqlalchemy/ext/asyncio/session.py +++ b/lib/sqlalchemy/ext/asyncio/session.py @@ -628,8 +628,7 @@ class AsyncSession(ReversibleProxy[Session]): """Return an instance based on the given primary key identifier, or raise an exception if not found. - Raises ``sqlalchemy.orm.exc.NoResultFound`` if the query selects - no rows. + Raises :class:`_exc.NoResultFound` if the query selects no rows. ..versionadded: 2.0.22 diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index af496b245f..3489c15fd6 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -2787,11 +2787,10 @@ class Query( def one(self) -> _T: """Return exactly one result or raise an exception. - Raises ``sqlalchemy.orm.exc.NoResultFound`` if the query selects - no rows. Raises ``sqlalchemy.orm.exc.MultipleResultsFound`` - if multiple object identities are returned, or if multiple - rows are returned for a query that returns only scalar values - as opposed to full identity-mapped entities. + Raises :class:`_exc.NoResultFound` if the query selects no rows. + Raises :class:`_exc.MultipleResultsFound` if multiple object identities + are returned, or if multiple rows are returned for a query that returns + only scalar values as opposed to full identity-mapped entities. Calling :meth:`.one` results in an execution of the underlying query. @@ -2811,7 +2810,7 @@ class Query( def scalar(self) -> Any: """Return the first element of the first result or None if no rows present. If multiple rows are returned, - raises MultipleResultsFound. + raises :class:`_exc.MultipleResultsFound`. >>> session.query(Item).scalar() diff --git a/lib/sqlalchemy/orm/scoping.py b/lib/sqlalchemy/orm/scoping.py index a0e9f17e4f..df5a6534dc 100644 --- a/lib/sqlalchemy/orm/scoping.py +++ b/lib/sqlalchemy/orm/scoping.py @@ -1086,8 +1086,7 @@ class scoped_session(Generic[_S]): Proxied for the :class:`_orm.Session` class on behalf of the :class:`_orm.scoping.scoped_session` class. - Raises ``sqlalchemy.orm.exc.NoResultFound`` if the query - selects no rows. + Raises :class:`_exc.NoResultFound` if the query selects no rows. For a detailed documentation of the arguments see the method :meth:`.Session.get`. diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index 6cd7cd6339..f8ad6fa6a4 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -3718,8 +3718,7 @@ class Session(_SessionClassMethods, EventTarget): """Return exactly one instance based on the given primary key identifier, or raise an exception if not found. - Raises ``sqlalchemy.orm.exc.NoResultFound`` if the query - selects no rows. + Raises :class:`_exc.NoResultFound` if the query selects no rows. For a detailed documentation of the arguments see the method :meth:`.Session.get`. -- 2.47.3