Skip to content

Commit 9486b6c

Browse files
authored
Merge pull request pallets#4342 from pallets/deprecate-req-ctx-g
deprecate `RequestContext.g`
2 parents 04c6a85 + c8ddb94 commit 9486b6c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Unreleased
2929
- ``add_etags`` is renamed to ``etag``.
3030
- ``filename`` is renamed to ``path``.
3131

32+
- The ``RequestContext.g`` property is deprecated. Use ``g`` directly
33+
or ``AppContext.g`` instead. :issue:`3898`
3234
- ``copy_current_request_context`` can decorate async functions.
3335
:pr:`4303`
3436

src/flask/ctx.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,29 @@ def __init__(
332332
self._after_request_functions: t.List[AfterRequestCallable] = []
333333

334334
@property
335-
def g(self) -> AppContext:
335+
def g(self) -> _AppCtxGlobals:
336+
import warnings
337+
338+
warnings.warn(
339+
"Accessing 'g' on the request context is deprecated and"
340+
" will be removed in Flask 2.2. Access `g` directly or from"
341+
"the application context instead.",
342+
DeprecationWarning,
343+
stacklevel=2,
344+
)
336345
return _app_ctx_stack.top.g
337346

338347
@g.setter
339-
def g(self, value: AppContext) -> None:
348+
def g(self, value: _AppCtxGlobals) -> None:
349+
import warnings
350+
351+
warnings.warn(
352+
"Setting 'g' on the request context is deprecated and"
353+
" will be removed in Flask 2.2. Set it on the application"
354+
" context instead.",
355+
DeprecationWarning,
356+
stacklevel=2,
357+
)
340358
_app_ctx_stack.top.g = value
341359

342360
def copy(self) -> "RequestContext":

0 commit comments

Comments
 (0)