Skip to content

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

Open
ericapisani wants to merge 10 commits into
major/3.0from
py-2381-take-4
Open

ericapisani wants to merge 10 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 📊

✅ 58338 passed | ⏭️ 2727 skipped | Total: 61065 | Pass Rate: 95.53% | Execution Time: 161m 43s

📊 Comparison with Base Branch

Metric Change
Total Tests 📉 -78948
Passed Tests 📉 -74455
Failed Tests —
Skipped Tests 📉 -4493

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 2060 uncovered lines.
❌ Project coverage is 90.11%. Comparing base (08212cd) to head (ee53b91).

Coverage diff
@@            Coverage Diff             @@
##        master       #PR       +/-##
==========================================
- Coverage    90.37%    90.11%    -0.26%
==========================================
  Files          199       182       -17
  Lines        26526     20828     -5698
  Branches      9866      7256     -2610
==========================================
+ Hits         23971     18768     -5203
- Misses        2555      2060      -495
- Partials      1495      1210      -285

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

This branch has not been deployed

No deployments
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.

1 participant