fix(deletions): Avoid DoesNotExist crash when FK target is already deleted#112375
Merged
swartzrock merged 1 commit intomasterfrom Apr 7, 2026
Merged
fix(deletions): Avoid DoesNotExist crash when FK target is already deleted#112375swartzrock merged 1 commit intomasterfrom
swartzrock merged 1 commit intomasterfrom
Conversation
cef1e78 to
68e8db2
Compare
krithikravi
reviewed
Apr 7, 2026
| # Verify the error path in DetectorDeletionTask was actually exercised. | ||
| mock_remove_seat_subscriptions.assert_called_once() | ||
|
|
||
| def test_dangling_workflow_condition_group(self) -> None: |
Member
There was a problem hiding this comment.
is there a test that reproduces the exact bug? like the repeating queuing and failure to delete
Member
Author
There was a problem hiding this comment.
how does test_dangling_fk_causes_stuck_deletion_loop() look?
3756a03 to
4ec6d3b
Compare
…leted DetectorDeletionTask and WorkflowDeletionTask both accessed FK descriptors (instance.workflow_condition_group, instance.when_condition_group) to check whether to include a related DataConditionGroup in child relations. When the referenced row has already been deleted, Django raises DoesNotExist. Because _run_deletion swallows all exceptions in production without re-raising, this caused the deletion task to silently fail and enter an infinite retry loop via reattempt_deletions. Orgs with detectors or workflows in this state can stay stuck in DELETION_IN_PROGRESS indefinitely. Fix by reading the raw FK id field instead of going through the descriptor, which avoids the database lookup and the potential DoesNotExist entirely. Fixes SENTRY-5M8C Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
4ec6d3b to
e2eee00
Compare
saponifi3d
approved these changes
Apr 7, 2026
Contributor
saponifi3d
left a comment
There was a problem hiding this comment.
lgtm - thanks for making this fix! 🙏
wedamija
approved these changes
Apr 7, 2026
george-sentry
pushed a commit
that referenced
this pull request
Apr 9, 2026
…leted (#112375) DetectorDeletionTask and WorkflowDeletionTask both accessed FK descriptors (instance.workflow_condition_group, instance.when_condition_group) to check whether to include a related DataConditionGroup in child relations. When the referenced row has already been deleted, Django raises DoesNotExist. Because _run_deletion swallows all exceptions in production without re-raising, this caused the deletion task to silently fail and enter an infinite retry loop via reattempt_deletions. Orgs with detectors or workflows in this state can stay stuck in DELETION_IN_PROGRESS indefinitely. Fix by reading the raw FK id field instead of going through the descriptor, which avoids the database lookup and the potential DoesNotExist entirely. Fixes [SENTRY-5M8C](https://sentry.sentry.io/issues/7344636431) Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DetectorDeletionTask and WorkflowDeletionTask both accessed FK descriptors (instance.workflow_condition_group, instance.when_condition_group) to check whether to include a related DataConditionGroup in child relations. When the referenced row has already been deleted, Django raises DoesNotExist.
Because _run_deletion swallows all exceptions in production without re-raising, this caused the deletion task to silently fail and enter an infinite retry loop via reattempt_deletions. Orgs with detectors or workflows in this state can stay stuck in DELETION_IN_PROGRESS indefinitely.
Fix by reading the raw FK id field instead of going through the descriptor, which avoids the database lookup and the potential DoesNotExist entirely.
Fixes SENTRY-5M8C