MCPcopy
hub / github.com/pallets-eco/flask-sqlalchemy / one_or_404

Method one_or_404

src/flask_sqlalchemy/query.py:50–61  ·  view source on GitHub ↗

Like :meth:`~sqlalchemy.orm.Query.one` but aborts with a ``404 Not Found`` error instead of raising ``NoResultFound`` or ``MultipleResultsFound``. :param description: A custom message to show on the error page. .. versionadded:: 3.0

(self, description: str | None = None)

Source from the content-addressed store, hash-verified

48 return rv
49
50 def one_or_404(self, description: str | None = None) -> t.Any:
51 """Like :meth:`~sqlalchemy.orm.Query.one` but aborts with a ``404 Not Found``
52 error instead of raising ``NoResultFound`` or ``MultipleResultsFound``.
53
54 :param description: A custom message to show on the error page.
55
56 .. versionadded:: 3.0
57 """
58 try:
59 return self.one()
60 except (sa_exc.NoResultFound, sa_exc.MultipleResultsFound):
61 abort(404, description=description)
62
63 def paginate(
64 self,

Callers 2

test_view_one_or_404Function · 0.45
test_one_or_404Function · 0.45

Calls

no outgoing calls

Tested by 2

test_view_one_or_404Function · 0.36
test_one_or_404Function · 0.36