Skip to content

fix(dedupe): Track seen exceptions via attribute instead of ContextVar - #7533

Merged
ericapisani merged 15 commits into
major/3.0from
py-2381-take-4
Oct 5, 2026
Merged

ericapisani merged 15 commits into
major/3.0from
py-2381-take-4

Conversation

@ericapisani

@ericapisani ericapisani commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Replace DedupeIntegration's weakref/ContextVar-based "last seen"
tracking with a _handled_by_sentry flag set directly on the
exception. This avoids the contextvar leaking across async contexts
and removes the need for reset_last_seen(), which the client used
to call after before_send dropped an exception.

Add a regression test for the case where the same exception instance
is re-raised (e.g. Django re-raising in middleware after a view
already handled it) to confirm it's still deduped correctly.

Fixes PY-2381
Fixes #6094

@linear-code

linear-code Bot commented Sep 17, 2026

Copy link
Copy Markdown

PY-2381

@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Codecov Results 📊

✅ 56706 passed | ⏭️ 2727 skipped | Total: 59433 | Pass Rate: 95.41% | Execution Time: 156m 7s

📊 Comparison with Base Branch

Metric Change
Total Tests 📉 -80918
Passed Tests 📉 -76423
Failed Tests —
Skipped Tests 📉 -4495

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 2075 uncovered lines.
❌ Project coverage is 90%. Comparing base (185fb9c) to head (63e1e48).

Coverage diff
@@            Coverage Diff             @@
##        master       #PR       +/-##
==========================================
- Coverage    90.35%    90.00%    -0.35%
==========================================
  Files          202       185       -17
  Lines        26551     20741     -5810
  Branches      9856      7158     -2698
==========================================
+ Hits         23988     18666     -5322
- Misses        2563      2075      -488
- Partials      1487      1205      -282

Generated by Codecov Action

@ericapisani ericapisani changed the title (WIP) Attempt #1 fix(dedupe): Track seen exceptions via attribute instead of ContextVar Sep 18, 2026
@ericapisani
ericapisani marked this pull request as ready for review September 18, 2026 19:10
@ericapisani
ericapisani requested a review from a team as a code owner September 18, 2026 19:10

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

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 900ad90. Configure here.

Comment thread sentry_sdk/integrations/dedupe.py
The test asserted that a payload referenced from a captured exception's
traceback is garbage collected. Binding the exception in the test
function's own frame kept it reachable via the frame's locals under
coverage tracing, so the assertion failed on CI (seen on 3.8 and 3.12).

Raise and capture inside a nested helper so the exception never lands in
the test function's locals.
@ericapisani
ericapisani merged commit dd7a983 into major/3.0 Oct 5, 2026
147 checks passed
@ericapisani
ericapisani deleted the py-2381-take-4 branch October 5, 2026 12:24
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.

2 participants