Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Unreleased
If subclasses were overriding these methods, the old signature is detected,
shows a deprecation warning, and will continue to work during the
deprecation period. :issue:`5815`
- The ``should_ignore_error`` is deprecated. Handle errors as needed in
teardown handlers instead. :issue:`5816`
- ``template_filter``, ``template_test``, and ``template_global`` decorators
can be used without parentheses. :issue:`5729`
- ``redirect`` returns a ``303`` status code by default instead of ``302``.
Expand Down
17 changes: 16 additions & 1 deletion src/flask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,17 @@ def full_dispatch_request(self, ctx: AppContext) -> Response:

.. versionadded:: 0.7
"""
if not self._got_first_request and self.should_ignore_error is not None:
import warnings

warnings.warn(
"The 'should_ignore_error' method is deprecated and will"
" be removed in Flask 3.3. Handle errors as needed in"
" teardown handlers instead.",
DeprecationWarning,
stacklevel=1,
)

self._got_first_request = True

try:
Expand Down Expand Up @@ -1576,7 +1587,11 @@ def wsgi_app(
if "werkzeug.debug.preserve_context" in environ:
environ["werkzeug.debug.preserve_context"](ctx)

if error is not None and self.should_ignore_error(error):
if (
error is not None
and self.should_ignore_error is not None
and self.should_ignore_error(error)
):
error = None

ctx.pop(error)
Expand Down
17 changes: 9 additions & 8 deletions src/flask/sansio/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,15 +922,16 @@ def trap_http_exception(self, e: Exception) -> bool:

return False

def should_ignore_error(self, error: BaseException | None) -> bool:
"""This is called to figure out if an error should be ignored
or not as far as the teardown system is concerned. If this
function returns ``True`` then the teardown handlers will not be
passed the error.
should_ignore_error: None = None
"""If this method returns ``True``, the error will not be passed to
teardown handlers, and the context will not be preserved for
debugging.

.. versionadded:: 0.10
"""
return False
.. deprecated:: 3.2
Handle errors as needed in teardown handlers instead.

.. versionadded:: 0.10
"""

def redirect(self, location: str, code: int = 303) -> BaseResponse:
"""Create a redirect response object.
Expand Down