ref: Remove contextvars compatibility code in new major - #6918
Conversation
Drop the contextvars compatibility layer that supported Python 3.6 (aiocontextvars), old gevent (<20.9.0), and old greenlet (<0.5). - Remove `_is_contextvars_broken`, `_make_threadlocal_contextvars`, `_get_contextvars`, `HAS_REAL_CONTEXTVARS`, and `CONTEXTVARS_ERROR_MESSAGE` from utils.py - Use `from contextvars import ContextVar` directly everywhere - Remove `unsafe_context_data` parameter from `SentryAsgiMiddleware` - Remove contextvars checks from aiohttp, asgi, tornado, sanic, and django integrations - Add version deprecation warnings for gevent <20.9.0 and greenlet <0.5 in `_check_version_deprecations()` - Add type annotations to all ContextVar declarations
Codecov Results 📊✅ 89524 passed | ❌ 1 failed | ⏭️ 5441 skipped | Total: 94966 | Pass Rate: 94.27% | Execution Time: 331m 25s 📊 Comparison with Base Branch
➕ New Tests (1)View new tests
❌ Failed Tests
|
| File | Patch % | Lines |
|---|---|---|
| sentry_sdk/_init_implementation.py | 88.89% |
Coverage diff
@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 89.91% 90.09% +0.18%
==========================================
Files 193 186 -7
Lines 24825 23654 -1171
Branches 8912 8538 -374
==========================================
+ Hits 22321 21311 -1010
- Misses 2504 2343 -161
- Partials 1414 1368 -46Generated by Codecov Action
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 7d7ac53. Configure here.

Description
Drop the contextvars compatibility layer that supported Python 3.6 (aiocontextvars), old gevent (<20.9.0), and old greenlet (<0.5).
Warn if using an older version of either during setup.
This allows us to remove the whole machinery around checking whether contextvars are safe to use and replacing them if not.
Note: 3.6 tests are expected to fail on this. They'll be dropped in #6904
Issues
Closes #5037
Reminders
uv run ruff.feat:,fix:,ref:,meta:)