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

Method first_or_404

src/flask_sqlalchemy/query.py:37–48  ·  view source on GitHub ↗

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

(self, description: str | None = None)

Source from the content-addressed store, hash-verified

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``
39 error instead of returning ``None``.
40
41 :param description: A custom message to show on the error page.
42 """
43 rv = self.first()
44
45 if rv is None:
46 abort(404, description=description)
47
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``

Callers 2

test_first_or_404Function · 0.45
test_first_or_404Function · 0.45

Calls 1

firstMethod · 0.80

Tested by 2

test_first_or_404Function · 0.36
test_first_or_404Function · 0.36