deprecate RequestContext.g
This commit is contained in:
parent
04c6a85518
commit
c8ddb948f6
2 changed files with 22 additions and 2 deletions
|
|
@ -29,6 +29,8 @@ Unreleased
|
||||||
- ``add_etags`` is renamed to ``etag``.
|
- ``add_etags`` is renamed to ``etag``.
|
||||||
- ``filename`` is renamed to ``path``.
|
- ``filename`` is renamed to ``path``.
|
||||||
|
|
||||||
|
- The ``RequestContext.g`` property is deprecated. Use ``g`` directly
|
||||||
|
or ``AppContext.g`` instead. :issue:`3898`
|
||||||
- ``copy_current_request_context`` can decorate async functions.
|
- ``copy_current_request_context`` can decorate async functions.
|
||||||
:pr:`4303`
|
:pr:`4303`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -332,11 +332,29 @@ class RequestContext:
|
||||||
self._after_request_functions: t.List[AfterRequestCallable] = []
|
self._after_request_functions: t.List[AfterRequestCallable] = []
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def g(self) -> AppContext:
|
def g(self) -> _AppCtxGlobals:
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
warnings.warn(
|
||||||
|
"Accessing 'g' on the request context is deprecated and"
|
||||||
|
" will be removed in Flask 2.2. Access `g` directly or from"
|
||||||
|
"the application context instead.",
|
||||||
|
DeprecationWarning,
|
||||||
|
stacklevel=2,
|
||||||
|
)
|
||||||
return _app_ctx_stack.top.g
|
return _app_ctx_stack.top.g
|
||||||
|
|
||||||
@g.setter
|
@g.setter
|
||||||
def g(self, value: AppContext) -> None:
|
def g(self, value: _AppCtxGlobals) -> None:
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
warnings.warn(
|
||||||
|
"Setting 'g' on the request context is deprecated and"
|
||||||
|
" will be removed in Flask 2.2. Set it on the application"
|
||||||
|
" context instead.",
|
||||||
|
DeprecationWarning,
|
||||||
|
stacklevel=2,
|
||||||
|
)
|
||||||
_app_ctx_stack.top.g = value
|
_app_ctx_stack.top.g = value
|
||||||
|
|
||||||
def copy(self) -> "RequestContext":
|
def copy(self) -> "RequestContext":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue