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)
| 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`` |