-
Notifications
You must be signed in to change notification settings - Fork 505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 Fix detection of contextvars compatibility with Gevent 20.9.0+ #1157
🐛 Fix detection of contextvars compatibility with Gevent 20.9.0+ #1157
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I don't think this can have tests unless you want to play around with the version matrix in tox, barely worth it
Thanks for the reviews @untitaker and @ahmedetefy! 🚀 Dang it, sorry for the linter warnings, I just ran them locally and fixed them (hopefully 🤞). I agree that all the extra complexity for testing different versions of Gevent with different versions of Python doesn't seem worth it as it's probably more of an edge case. Nevertheless, let me know if they are needed and I can give that a try. |
Thanks @tiangolo ! |
Awesome! Thanks for the quick response/review and merge! 🚀 Do you have any estimate of when this could be included in a release? |
Anytime! Yep will cut a patch today |
Woohoo! Awesome, thanks a lot! 🚀 |
🐛 Fix detection of contextvars compatibility with Gevent 20.9.0+
This is described in #1063, and this PR would fix it (it should at least).
Description
The current implementation checks if Gevent patched contextvars, but:
Ref: https://github.com/gevent/gevent/blob/83c9e2ae5b0834b8f84233760aabe82c3ba065b4/src/gevent/monkey.py#L604-L609
This PR updates the implementation to check the version of Gevent and Python to account for that.
Use Case
I'm migrating a code base with a couple of apps from Flask to FastAPI. During the migration both Flask and FastAPI are available at the same time, sharing a lot of the code and tests.
The Flask app is currently deployed with Gevent, so the tests use Gevent's monkey patching.
The FastAPI app uses the
SentryAsgiMiddleware
, which internally usescontextvars
to store and handle all the Sentry stuff per request. And that in turn uses this utility function to check if the current environment has working contextvars available.So, with Python 3.7+ and a recent installation of Gevent monkey patching stuff, Sentry errors out complaining about broken contextvars, but it seems it's actually just a false positive.