Skip to content

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

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

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

66097 passed | ⏭️ 2999 skipped | Total: 69096 | Pass Rate: 95.66% | Execution Time: 188m 32s

📊 Comparison with Base Branch

Metric Change
Total Tests 📉 -68610
Passed Tests 📉 -64487
Failed Tests
Skipped Tests 📉 -4123

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 2074 uncovered lines.
❌ Project coverage is 90.09%. Comparing base (f46fbb6) to head (900ad90).

Coverage diff
@@            Coverage Diff             @@
##        master       #PR       +/-##
==========================================
- Coverage    90.28%    90.09%    -0.19%
==========================================
  Files          193       179       -14
  Lines        25729     20923     -4806
  Branches      9496      7522     -1974
==========================================
+ Hits         23228     18849     -4379
- Misses        2501      2074      -427
- Partials      1432      1180      -252

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.

else:
with capture_internal_exceptions():
exc._handled_by_sentry = True
return event

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Dropped events still mark exceptions handled

Medium Severity

The _handled_by_sentry flag is set in the event processor, which runs before before_send. If before_send then drops the event, the flag stays set, so a later capture of the same exception instance is discarded by DedupeIntegration even though Sentry never received the first one. This reintroduces the previously fixed dropped-event dedupe bug.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 900ad90. Configure here.

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