mirror of https://github.com/pallets/flask.git
update error message for after_this_request and copy_current_request_context
This commit is contained in:
parent
633449a36c
commit
b1a00ebc4c
|
@ -15,7 +15,7 @@ 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
|
- Clearer error message when ``after_this_request`` is used outside a
|
||||||
request context. :issue:`4333`
|
request context. :issue:`4333`
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -131,14 +131,14 @@ def after_this_request(f: AfterRequestCallable) -> AfterRequestCallable:
|
||||||
.. versionadded:: 0.9
|
.. versionadded:: 0.9
|
||||||
"""
|
"""
|
||||||
top = _request_ctx_stack.top
|
top = _request_ctx_stack.top
|
||||||
|
|
||||||
if top is None:
|
if top is None:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"This decorator can only be used at local scopes "
|
"This decorator can only be used when a request context is"
|
||||||
"when a request context is on the stack. For instance within "
|
" active, such as within a view function."
|
||||||
"view functions."
|
|
||||||
)
|
)
|
||||||
top._after_request_functions.append(f)
|
|
||||||
|
|
||||||
|
top._after_request_functions.append(f)
|
||||||
return f
|
return f
|
||||||
|
|
||||||
|
|
||||||
|
@ -167,12 +167,13 @@ def copy_current_request_context(f: t.Callable) -> t.Callable:
|
||||||
.. versionadded:: 0.10
|
.. versionadded:: 0.10
|
||||||
"""
|
"""
|
||||||
top = _request_ctx_stack.top
|
top = _request_ctx_stack.top
|
||||||
|
|
||||||
if top is None:
|
if top is None:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"This decorator can only be used at local scopes "
|
"This decorator can only be used when a request context is"
|
||||||
"when a request context is on the stack. For instance within "
|
" active, such as within a view function."
|
||||||
"view functions."
|
|
||||||
)
|
)
|
||||||
|
|
||||||
reqctx = top.copy()
|
reqctx = top.copy()
|
||||||
|
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
|
|
Loading…
Reference in New Issue