fix error message

This commit is contained in:
Yourun-Proger 2021-11-19 23:09:38 +03:00 committed by David Lord
parent 7b0c82dfdc
commit 633449a36c
No known key found for this signature in database
GPG Key ID: 7A1C87E3F5BC42A8
2 changed files with 11 additions and 1 deletions

View File

@ -15,6 +15,8 @@ Unreleased
- ``app.json_encoder`` and ``json_decoder`` are only passed to - ``app.json_encoder`` and ``json_decoder`` are only passed to
``dumps`` and ``loads`` if they have custom behavior. This improves ``dumps`` and ``loads`` if they have custom behavior. This improves
performance, mainly on PyPy. :issue:`4349` performance, mainly on PyPy. :issue:`4349`
- Fix error message for ``after_this_request`` when it used outside
request context. :issue:`4333`
Version 2.0.2 Version 2.0.2

View File

@ -130,7 +130,15 @@ def after_this_request(f: AfterRequestCallable) -> AfterRequestCallable:
.. versionadded:: 0.9 .. versionadded:: 0.9
""" """
_request_ctx_stack.top._after_request_functions.append(f) top = _request_ctx_stack.top
if top is None:
raise RuntimeError(
"This decorator can only be used at local scopes "
"when a request context is on the stack. For instance within "
"view functions."
)
top._after_request_functions.append(f)
return f return f