Repository navigation
fix(deletions): Avoid DoesNotExist crash when FK target is already deleted - #112375
Merged
Merged
Conversation
swartzrock
force-pushed
the
swartzrock/workflow-deletion-bug
branch
from
April 7, 2026 16:46
cef1e78 to
68e8db2
Compare
krithikravi
reviewed
Apr 7, 2026
| @@ -176,6 +176,20 @@ def test_delete_uptime_detector_succeeds_when_remove_seat_fails( | |||
| # Verify the error path in DetectorDeletionTask was actually exercised. | |||
| mock_remove_seat_subscriptions.assert_called_once() | |||
|
|
|||
| def test_dangling_workflow_condition_group(self) -> None: | |||
Contributor
There was a problem hiding this comment.
is there a test that reproduces the exact bug? like the repeating queuing and failure to delete
Author
There was a problem hiding this comment.
how does test_dangling_fk_causes_stuck_deletion_loop() look?
swartzrock
force-pushed
the
swartzrock/workflow-deletion-bug
branch
2 times, most recently
from
April 7, 2026 17:25
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>
swartzrock
force-pushed
the
swartzrock/workflow-deletion-bug
branch
from
April 7, 2026 18:44
4ec6d3b to
e2eee00
Compare
swartzrock
marked this pull request as ready for review
April 7, 2026 18:44
saponifi3d
approved these changes
Apr 7, 2026
saponifi3d
left a comment
Contributor
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 branch was successfully deployed
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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