Skip to content

Remove references to RuleFireHistory#115036

Merged
ceorourke merged 11 commits intomasterfrom
ceorourke/ISWF-2601
May 7, 2026
Merged

Remove references to RuleFireHistory#115036
ceorourke merged 11 commits intomasterfrom
ceorourke/ISWF-2601

Conversation

@ceorourke
Copy link
Copy Markdown
Member

@ceorourke ceorourke commented May 6, 2026

Remove a lot (but not all) of references to RuleFireHistory. This table is completely empty as we don't write to it anymore and it's passed the retention period so the records have been cleaned up. I'm working on removing the remaining references #115035 which are tied to notifications but I need to do a migration to remove the FK on NotificationMessage first and this is still a large diff so I chose to keep it separate.

@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 6, 2026

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label May 6, 2026
@ceorourke ceorourke changed the title Remove more references to RuleFireHistory Remove references to RuleFireHistory May 7, 2026
@ceorourke ceorourke marked this pull request as ready for review May 7, 2026 17:06
@ceorourke ceorourke requested review from a team as code owners May 7, 2026 17:06
@ceorourke ceorourke requested review from a team and removed request for a team May 7, 2026 17:06
Comment thread src/sentry/rules/history/backends/postgres.py
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c9938f9. Configure here.

Comment thread src/sentry/rules/history/backends/postgres.py
Comment thread src/sentry/rules/history/backends/postgres.py
Copy link
Copy Markdown
Member

@wedamija wedamija left a comment

Choose a reason for hiding this comment

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

🔥

Comment thread src/sentry/deletions/defaults/rule.py
Comment thread src/sentry/deletions/defaults/rulefirehistory.py
Comment thread src/sentry/deletions/__init__.py
Comment on lines +66 to +67
FROM workflow_engine_workflowfirehistory
WHERE workflow_id = %s AND date_added >= %s AND date_added < %s
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.

I assume we backfilled this data and it's all in the workflowfirehistory table now?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure if we backfilled it but rather started writing to it instead and we only need so much history. I forget the exact retention of rulefirehistory but it's totally empty because of the cleanup tasks

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.

Oh, if it's totally empty you can ignore my comments about the deletion code then

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

oh lol ok

Comment on lines -88 to -94
def record(
self,
rule: Rule,
group: Group,
event_id: str | None = None,
notification_uuid: str | None = None,
) -> RuleFireHistory | None:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: When the organizations:workflow-engine-issue-alert-endpoints-get flag is off, fetch_rule_hourly_stats and fetch_rule_groups_paginated receive a Rule object but expect a Workflow, causing them to silently return empty data.
Severity: HIGH

Suggested Fix

Reintroduce logic to handle both Rule and Workflow objects passed as the target argument. This could involve checking the type of target and using a helper like the removed get_rule_workflow_ids to correctly retrieve the workflow_id when a Rule object is provided, ensuring backward compatibility when the feature flag is disabled.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/sentry/rules/history/backends/postgres.py#L88-L94

Potential issue: The functions `fetch_rule_hourly_stats` and
`fetch_rule_groups_paginated` were updated to assume their `target` argument is always a
`Workflow` object. However, when the
`organizations:workflow-engine-issue-alert-endpoints-get` feature flag is disabled,
legacy API endpoints pass a `Rule` object instead. The functions then use `target.id`
(which is a `Rule.id`) to query the `workflow_engine_workflowfirehistory` table, which
expects a `Workflow.id`. Since `Rule.id` and `Workflow.id` are from different tables,
the query finds no match and silently returns empty history and stats for legacy rules,
breaking functionality for users without the feature flag enabled.

@ceorourke ceorourke merged commit 06ac443 into master May 7, 2026
69 checks passed
@ceorourke ceorourke deleted the ceorourke/ISWF-2601 branch May 7, 2026 18:54
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