deprecate should_ignore_error (#5899)

This commit is contained in:
David Lord 2026-01-24 19:53:11 -08:00 committed by GitHub
commit 4b8bde97d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 9 deletions

View file

@ -14,6 +14,8 @@ Unreleased
If subclasses were overriding these methods, the old signature is detected, If subclasses were overriding these methods, the old signature is detected,
shows a deprecation warning, and will continue to work during the shows a deprecation warning, and will continue to work during the
deprecation period. :issue:`5815` 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 - ``template_filter``, ``template_test``, and ``template_global`` decorators
can be used without parentheses. :issue:`5729` can be used without parentheses. :issue:`5729`
- ``redirect`` returns a ``303`` status code by default instead of ``302``. - ``redirect`` returns a ``303`` status code by default instead of ``302``.

View file

@ -995,6 +995,17 @@ class Flask(App):
.. versionadded:: 0.7 .. 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 self._got_first_request = True
try: try:
@ -1576,7 +1587,11 @@ class Flask(App):
if "werkzeug.debug.preserve_context" in environ: if "werkzeug.debug.preserve_context" in environ:
environ["werkzeug.debug.preserve_context"](ctx) 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 error = None
ctx.pop(error) ctx.pop(error)

View file

@ -922,15 +922,16 @@ class App(Scaffold):
return False return False
def should_ignore_error(self, error: BaseException | None) -> bool: should_ignore_error: None = None
"""This is called to figure out if an error should be ignored """If this method returns ``True``, the error will not be passed to
or not as far as the teardown system is concerned. If this teardown handlers, and the context will not be preserved for
function returns ``True`` then the teardown handlers will not be debugging.
passed the error.
.. deprecated:: 3.2
Handle errors as needed in teardown handlers instead.
.. versionadded:: 0.10 .. versionadded:: 0.10
""" """
return False
def redirect(self, location: str, code: int = 303) -> BaseResponse: def redirect(self, location: str, code: int = 303) -> BaseResponse:
"""Create a redirect response object. """Create a redirect response object.