Skip to content

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

Merged
sentrivana merged 8 commits into
major/3.0from
ivana/major/drop-contextvars
Aug 4, 2026
Merged

ref: Remove contextvars compatibility code in new major#6918
sentrivana merged 8 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 📊

89524 passed | ❌ 1 failed | ⏭️ 5441 skipped | Total: 94966 | Pass Rate: 94.27% | Execution Time: 331m 25s

📊 Comparison with Base Branch

Metric Change
Total Tests 📉 -6836
Passed Tests 📉 -6039
Failed Tests 📈 +1
Skipped Tests 📉 -798

➕ New Tests (1)

View new tests
  • test_continuous_profiler_auto_start_and_stop_sampled_span_streaming[experiment-thread]
    • File: tests.profiler.test_continuous_profiler
    • Status: ❌ Failing

❌ Failed Tests

test_continuous_profiler_auto_start_and_stop_sampled_span_streaming[experiment-thread]

File: tests.profiler.test_continuous_profiler
Suite: py3.14t-common
Error: AssertionError: profiler should not be running assert '94fcf5220e9f41f5aca1a84cea6f200d' is None + where '94fcf5220e9f41f5aca1a84cea6f200d' = get_profiler_id()

Stack Trace
tests/profiler/test_continuous_profiler.py:896: in test_continuous_profiler_auto_start_and_stop_sampled_span_streaming
    assert get_profiler_id() is None, "profiler should not be running"
E   AssertionError: profiler should not be running
E   assert '94fcf5220e9f41f5aca1a84cea6f200d' is None
E    +  where '94fcf5220e9f41f5aca1a84cea6f200d' = get_profiler_id()

✅ Patch coverage is 94.87%. Project has 2343 uncovered lines.
✅ Project coverage is 90.09%. 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.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       -46

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
@sentrivana
sentrivana merged commit c93541c into major/3.0 Aug 4, 2026
126 of 127 checks passed
@sentrivana
sentrivana deleted the ivana/major/drop-contextvars branch August 4, 2026 08:33
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