fix(organization) Fix an issue with deleting an older Organization#111869
Merged
swartzrock merged 1 commit intomasterfrom Mar 31, 2026
Merged
fix(organization) Fix an issue with deleting an older Organization#111869swartzrock merged 1 commit intomasterfrom
swartzrock merged 1 commit intomasterfrom
Conversation
This is a deletion ordering bug introduced when Workflow was added to the org deletion task. Workflow should be appended before Environment in the relation list, not after. Since it has an FK pointing at Environment, it needs to be cleaned up first.
markstory
approved these changes
Mar 31, 2026
| AlertRule, | ||
| Release, | ||
| Project, | ||
| Workflow, |
Member
There was a problem hiding this comment.
Since Environment doesn't have a deletion task already, this is worth a shot. Workflow doesn't have Environment as a child so we shouldn't break deletions in a new way.
dashed
pushed a commit
that referenced
this pull request
Apr 1, 2026
…111869) When the task tries to delete sentry_environment rows, Django's cascade sees that workflow_engine_workflow rows still reference them. It tries to cascade-delete those workflows in Python — but those rows haven't gone through their own proper deletion task yet, and if Workflow has any child relations or outbox requirements, the inline cascade may fail or leave orphans. This is a deletion ordering bug introduced when Workflow was added to the org deletion task. Workflow should be appended before Environment in the relation list, not after. Since it has an FK pointing at Environment, it needs to be cleaned up first. Fixed by moving the Workflow relation earlier in get_child_relations, before Environment. ## Investigation I ran a query for child rows of an organization that was failing to delete, and `Environment` was the top in the list that still had undeleted rows. This indicated a dependent table that was not getting rows related to this Organization removed. table_name | row_count -- | -- sentry_externalissue | 748 sentry_promptsactivity | 183 sentry_environment | 177 workflow_engine_workflow | 9 sentry_dashboard | 9 sentry_discoversavedquery | 7
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.
When the task tries to delete sentry_environment rows, Django's cascade sees that workflow_engine_workflow rows still reference them. It tries to cascade-delete those workflows in Python — but those rows haven't gone through their own proper deletion task yet, and if Workflow has any child relations or outbox requirements, the inline cascade may fail or leave orphans.
This is a deletion ordering bug introduced when Workflow was added to the org deletion task. Workflow should be appended before Environment in the relation list, not after. Since it has an FK pointing at Environment, it needs to be cleaned up first.
Fixed by moving the Workflow relation earlier in get_child_relations, before Environment.
Investigation
I ran a query for child rows of an organization that was failing to delete, and
Environmentwas the top in the list that still had undeleted rows. This indicated a dependent table that was not getting rows related to this Organization removed.