Skip to content

ref: Remove contextvars compatibility code in new major - #6918

Open
sentrivana wants to merge 7 commits into
major/3.0from
ivana/major/drop-contextvars
Open

ref: Remove contextvars compatibility code in new major#6918
sentrivana wants to merge 7 commits into
major/3.0from
ivana/major/drop-contextvars

Conversation

@sentrivana

@sentrivana sentrivana commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

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

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
@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

96014 passed | ⏭️ 6397 skipped | Total: 102411 | Pass Rate: 93.75% | Execution Time: 340m 47s

📊 Comparison with Base Branch

Metric Change
Total Tests 📉 -2903
Passed Tests 📉 -2544
Failed Tests
Skipped Tests 📉 -359

All tests are passing successfully.

✅ Patch coverage is 94.87%. Project has 2486 uncovered lines.
❌ Project coverage is 89.72%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
sentry_sdk/_init_implementation.py 88.89% ⚠️ 2 Missing and 2 partials
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    89.83%    89.72%    -0.11%
==========================================
  Files          193       192        -1
  Lines        24588     24190      -398
  Branches      8744      8600      -144
==========================================
+ Hits         22089     21704      -385
- Misses        2499      2486       -13
- Partials      1400      1395        -5

Generated by Codecov Action

@sentrivana
sentrivana marked this pull request as ready for review July 29, 2026 11:25
@sentrivana
sentrivana requested a review from a team as a code owner July 29, 2026 11:25
Comment thread sentry_sdk/_init_implementation.py
Comment thread sentry_sdk/_init_implementation.py
Comment thread sentry_sdk/_init_implementation.py

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ 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.

Comment thread sentry_sdk/_init_implementation.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants