MagicStack / MagicStack/contextvars

Created in different context error

Open
#18 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
90
Forks
9
PR merge metrics
No merged PRs in 30d

Description

Hi all,

Everything has worked fine for ContextVarsScopeManager if I have only Fastapi application. But, When I tried to mount a Flask WSGIApplication to the Fastapi application, I've got an error from ContextVarsScopeManager as "<Token var=<ContextVar name='scope' at 0x7ff47d568a90> at 0x7ff47d61fe00> was created in a different Context". This error has been raised from after_request function of tracer.wrappers.fastapi.fastapi_wrapper module while trying to close scope. When I debugged the code, I have found out that "if token._var is not self" check into reset function of ContextVar class has caused this exception. I've created a sample project to reproduce the issue and shared it's Github url below.

Github url: https://github.com/gokhan721/opentracing_contextvar_work

Thanks.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ContextVarsScopeManager and the after_request function in tracer.wrappers.fastapi.fastapi_wrapper, then reproduce the failure using the linked sample project with a Flask WSGI application mounted in FastAPI. Done means closing the scope no longer raises the “created in a different Context” error in that setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
fastapi, flask, python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.