Skip to content

Commit

Permalink
Merge pull request pallets#4342 from pallets/deprecate-req-ctx-g
Browse files Browse the repository at this point in the history
deprecate `RequestContext.g`
  • Loading branch information
davidism authored Nov 16, 2021
2 parents 04c6a85 + c8ddb94 commit 9486b6c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Unreleased
- ``add_etags`` is renamed to ``etag``.
- ``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.
:pr:`4303`

Expand Down
22 changes: 20 additions & 2 deletions src/flask/ctx.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,29 @@ def __init__(
self._after_request_functions: t.List[AfterRequestCallable] = []

@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

@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

def copy(self) -> "RequestContext":
Expand Down

0 comments on commit 9486b6c

Please sign in to comment.