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

Method get_or_404

src/flask_sqlalchemy/query.py:23–35  ·  view source on GitHub ↗

Like :meth:`~sqlalchemy.orm.Query.get` but aborts with a ``404 Not Found`` error instead of returning ``None``. :param ident: The primary key to query. :param description: A custom message to show on the error page.

(self, ident: t.Any, description: str | None = None)

Source from the content-addressed store, hash-verified

21 """
22
23 def get_or_404(self, ident: t.Any, description: str | None = None) -> t.Any:
24 """Like :meth:`~sqlalchemy.orm.Query.get` but aborts with a ``404 Not Found``
25 error instead of returning ``None``.
26
27 :param ident: The primary key to query.
28 :param description: A custom message to show on the error page.
29 """
30 rv = self.get(ident)
31
32 if rv is None:
33 abort(404, description=description)
34
35 return rv
36
37 def first_or_404(self, description: str | None = None) -> t.Any:
38 """Like :meth:`~sqlalchemy.orm.Query.first` but aborts with a ``404 Not Found``

Callers 5

test_get_or_404Function · 0.45
test_view_get_or_404Function · 0.45
test_get_or_404Function · 0.45
get_postFunction · 0.45

Calls

no outgoing calls

Tested by 4

test_get_or_404Function · 0.36
test_view_get_or_404Function · 0.36
test_get_or_404Function · 0.36