Skip to content

Commit 5a2fc16

Browse files
committed
Prevent RuntimeError on context.detach with the same token
This happens for me when using werkzeug's debug=True. In this case, the token was already detached. But when I enter an expression into the debug console, we attempt to detach the token once more. This causes a RuntimeError, as expected: https://peps.python.org/pep-0567/#contextvars-contextvar. But if we set _ENVIRON_TOKEN to None after we detach, this won't happen.
1 parent 490580d commit 5a2fc16

File tree

1 file changed

+1
-0
lines changed
  • instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask

1 file changed

+1
-0
lines changed

instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ def _teardown_request(exc):
536536

537537
if flask.request.environ.get(_ENVIRON_TOKEN, None):
538538
context.detach(flask.request.environ.get(_ENVIRON_TOKEN))
539+
flask.request.environ[_ENVIRON_TOKEN] = None
539540

540541
return _teardown_request
541542

0 commit comments

Comments
 (0)