Skip to content

Conversation

@armenzg
Copy link
Member

@armenzg armenzg commented Oct 31, 2025

When deleting a GroupHistory record, Django would CASCADE to all records that reference it via prev_history, which can create circular dependency loops.

After this change, Django will just set prev_history=NULL on any records that reference it, breaking the circular chain.

Fixes SENTRY-3WN8 and SENTRY-3WKX.

When deleting a GroupHistory record, Django would CASCADE to all records that reference it via `prev_history`, which can create circular dependency loops.

After this change, Django will just set prev_history=NULL on any records that reference it, breaking the circular chain.

Fixes [SENTRY-3WN8](https://sentry.sentry.io/issues/6619377437/) and [SENTRY-3WKX](https://sentry.sentry.io/issues/6618890707/).
@armenzg armenzg requested a review from a team October 31, 2025 12:27
@armenzg armenzg self-assigned this Oct 31, 2025
@armenzg armenzg requested a review from a team as a code owner October 31, 2025 12:27
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 31, 2025
@github-actions
Copy link
Contributor

This PR has a migration; here is the generated SQL for src/sentry/migrations/1001_prevent_grouphistory_infinte_recursion.py

for 1001_prevent_grouphistory_infinte_recursion in sentry

--
-- Alter field prev_history on grouphistory
--
-- (no-op)

@armenzg
Copy link
Member Author

armenzg commented Oct 31, 2025

I prefer removing the field completely: #102473

@armenzg armenzg closed this Oct 31, 2025
@armenzg
Copy link
Member Author

armenzg commented Oct 31, 2025

That other PR will take multiple steps. Let's start with getting this one out the door.

@armenzg armenzg reopened this Oct 31, 2025
@armenzg armenzg requested review from markstory and wedamija October 31, 2025 12:57
armenzg added a commit that referenced this pull request Oct 31, 2025
While investigating #102470, I realized we don't actually use it for anything useful.

In order to delete the column, we first need to stop making any reference to it ([docs](https://develop.sentry.dev/backend/application-domains/database-migrations/#deleting-columns).
Copy link
Member

@markstory markstory left a comment

Choose a reason for hiding this comment

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

looks good to me. Instead of recursing deletes, django will only have to modify the one adjacent record.

@armenzg armenzg merged commit 52fde28 into master Oct 31, 2025
136 checks passed
@armenzg armenzg deleted the 0/group_history/deletions/armenzg branch October 31, 2025 14:05
isabellaenriquez pushed a commit that referenced this pull request Oct 31, 2025
When deleting a GroupHistory record, Django would CASCADE to all records
that reference it via `prev_history`, which can create circular
dependency loops.

After this change, Django will just set prev_history=NULL on any records
that reference it, breaking the circular chain.

Fixes [SENTRY-3WN8](https://sentry.sentry.io/issues/6619377437/) and
[SENTRY-3WKX](https://sentry.sentry.io/issues/6618890707/).
armenzg added a commit that referenced this pull request Oct 31, 2025
While investigating #102470, I realized we don't actually use it for
anything useful.

In order to delete the column, we first need to stop making use of it
(see
[docs](https://develop.sentry.dev/backend/application-domains/database-migrations/#deleting-columns)
for instructions).
jjbayer pushed a commit that referenced this pull request Nov 3, 2025
While investigating #102470, I realized we don't actually use it for
anything useful.

In order to delete the column, we first need to stop making use of it
(see
[docs](https://develop.sentry.dev/backend/application-domains/database-migrations/#deleting-columns)
for instructions).
armenzg added a commit that referenced this pull request Nov 3, 2025
This is how it used to be before #76608. Now that we have fixed the circular relationship (#102470) I believe we should give this approach another attempt.

Fixes [SENTRY-5BX2](https://sentry.sentry.io/issues/6993998110/):

For posterity:
```
OperationalError
canceling statement due to user request

SQL: SELECT "sentry_grouphistory"."id" AS "id" FROM "sentry_grouphistory" WHERE "sentry_grouphistory"."group_id" = %s ORDER BY 1 ASC LIMIT 100
```

The group in question has only been seen 4 times yet it has 905,729 rows of group history.
armenzg added a commit that referenced this pull request Nov 3, 2025
This is how it used to be before #76608. Now that we have fixed the
circular relationship (#102470) I believe we should give this approach
another attempt.

Fixes [SENTRY-5BX2](https://sentry.sentry.io/issues/6993998110/):

For posterity:
```
OperationalError
canceling statement due to user request

SQL: SELECT "sentry_grouphistory"."id" AS "id" FROM "sentry_grouphistory" WHERE "sentry_grouphistory"."group_id" = %s ORDER BY 1 ASC LIMIT 100
```

The group in question has only been seen 4 times yet it has 905,729 rows
of group history. This is caused by the priority of the group changing
back and forth between high and medium priority. We're investigating the
root cause of it.
shashjar pushed a commit that referenced this pull request Nov 4, 2025
When deleting a GroupHistory record, Django would CASCADE to all records
that reference it via `prev_history`, which can create circular
dependency loops.

After this change, Django will just set prev_history=NULL on any records
that reference it, breaking the circular chain.

Fixes [SENTRY-3WN8](https://sentry.sentry.io/issues/6619377437/) and
[SENTRY-3WKX](https://sentry.sentry.io/issues/6618890707/).
shashjar pushed a commit that referenced this pull request Nov 4, 2025
While investigating #102470, I realized we don't actually use it for
anything useful.

In order to delete the column, we first need to stop making use of it
(see
[docs](https://develop.sentry.dev/backend/application-domains/database-migrations/#deleting-columns)
for instructions).
shashjar pushed a commit that referenced this pull request Nov 4, 2025
This is how it used to be before #76608. Now that we have fixed the
circular relationship (#102470) I believe we should give this approach
another attempt.

Fixes [SENTRY-5BX2](https://sentry.sentry.io/issues/6993998110/):

For posterity:
```
OperationalError
canceling statement due to user request

SQL: SELECT "sentry_grouphistory"."id" AS "id" FROM "sentry_grouphistory" WHERE "sentry_grouphistory"."group_id" = %s ORDER BY 1 ASC LIMIT 100
```

The group in question has only been seen 4 times yet it has 905,729 rows
of group history. This is caused by the priority of the group changing
back and forth between high and medium priority. We're investigating the
root cause of it.
priscilawebdev pushed a commit that referenced this pull request Nov 6, 2025
This is how it used to be before #76608. Now that we have fixed the
circular relationship (#102470) I believe we should give this approach
another attempt.

Fixes [SENTRY-5BX2](https://sentry.sentry.io/issues/6993998110/):

For posterity:
```
OperationalError
canceling statement due to user request

SQL: SELECT "sentry_grouphistory"."id" AS "id" FROM "sentry_grouphistory" WHERE "sentry_grouphistory"."group_id" = %s ORDER BY 1 ASC LIMIT 100
```

The group in question has only been seen 4 times yet it has 905,729 rows
of group history. This is caused by the priority of the group changing
back and forth between high and medium priority. We're investigating the
root cause of it.
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.

3 participants