Skip to content

Commit 61f0177

Browse files
authored
chore(flask): avoid using deprecated internals (#4433)
The following flask attributes have been deprecated in flask v2.2.2 and will be removed in the next minor release: flask. _app_ctx_stack flask. _request_ctx_stack This change replaces deprecated methods with flask globals (flask.current_app and flask.request).
1 parent 96e6bca commit 61f0177

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

ddtrace/contrib/flask/helpers.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88

99
def get_current_app():
1010
"""Helper to get the flask.app.Flask from the current app context"""
11-
appctx = flask._app_ctx_stack.top
12-
if appctx:
13-
return appctx.app
11+
try:
12+
return flask.current_app
13+
except RuntimeError:
14+
# raised if current_app is None: https://github.com/pallets/flask/blob/2.1.3/src/flask/globals.py#L40
15+
pass
1416
return None
1517

1618

ddtrace/contrib/flask/patch.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,9 @@ def traced_jsonify(wrapped, instance, args, kwargs):
587587

588588
def _set_request_tags(span):
589589
try:
590-
request = flask._request_ctx_stack.top.request
590+
# raises RuntimeError if a request is not active:
591+
# https://github.com/pallets/flask/blob/2.1.3/src/flask/globals.py#L40
592+
request = flask.request
591593

592594
# DEV: This name will include the blueprint name as well (e.g. `bp.index`)
593595
if not span.get_tag(FLASK_ENDPOINT) and request.endpoint:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
flask: add support for flask v2.3. Remove deprecated usages of ``flask._app_ctx_stack`` and ``flask._request_ctx_stack``.

0 commit comments

Comments
 (0)