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.
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
"""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
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.
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()
<Item>
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`.
"""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`.