Skip to content

fix(organization) Fix an issue with deleting an older Organization#111869

Merged
swartzrock merged 1 commit intomasterfrom
swartzrock/fix-old-org-deletion
Mar 31, 2026
Merged

fix(organization) Fix an issue with deleting an older Organization#111869
swartzrock merged 1 commit intomasterfrom
swartzrock/fix-old-org-deletion

Conversation

@swartzrock
Copy link
Copy Markdown
Member

@swartzrock swartzrock commented Mar 31, 2026

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 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.
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 31, 2026
AlertRule,
Release,
Project,
Workflow,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@swartzrock swartzrock marked this pull request as ready for review March 31, 2026 04:34
@swartzrock swartzrock requested a review from a team as a code owner March 31, 2026 04:34
@swartzrock swartzrock merged commit da8d53b into master Mar 31, 2026
68 checks passed
@swartzrock swartzrock deleted the swartzrock/fix-old-org-deletion branch March 31, 2026 16:09
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants