Skip to content
Myr

Merge pull request #4348 from Yourun-proger/fix_msg

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix error message for `after_this_request` when used outside request context

authored by David Lord · committed by GitHub · parents 7b0c82d, b1a00eb · Browse files · 2 files+15 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+15 added−4 removed

  • other:+15 added−4 removed

2 files+15 added−4 removed

modified:src/flask/ctx.py+13 added-4 removed
128 unmodified lines
129 some headers without converting the return value into a response object.130131 .. versionadded:: 0.9132 """133 top = _request_ctx_stack.top134135 if top is None:136 raise RuntimeError(137 "This decorator can only be used when a request context is"138 " active, such as within a view function."139 )140133 _request_ctx_stack.top._after_request_functions.append(f)141 top._after_request_functions.append(f)142 return f143144145def copy_current_request_context(f: t.Callable) -> t.Callable:
20 unmodified lines
166167 .. versionadded:: 0.10168 """169 top = _request_ctx_stack.top170171 if top is None:172 raise RuntimeError(164 "This decorator can only be used at local scopes "165 "when a request context is on the stack. For instance within "166 "view functions."173 "This decorator can only be used when a request context is"174 " active, such as within a view function."175 )176177 reqctx = top.copy()178179 def wrapper(*args, **kwargs):180 with reqctx:
309 unmodified lines
modified:CHANGES.rst+2 added
13 unmodified lines
14 tracebacks when importing the application. :issue:`4307`15- ``app.json_encoder`` and ``json_decoder`` are only passed to16 ``dumps`` and ``loads`` if they have custom behavior. This improves17 performance, mainly on PyPy. :issue:`4349`18- Clearer error message when ``after_this_request`` is used outside a19 request context. :issue:`4333`202122Version 2.0.223-------------
1180 unmodified lines