Skip to content

Conversation

@cathteng
Copy link
Member

@cathteng cathteng commented Jan 10, 2026

Fully removes uses of workflow-engine-ui-links flag for issue alert firing.

We try to attach legacy_rule_id to the fake Rule's action when possible and attach the workflow_id. In downstream code we look for legacy_rule_id first to generate links, and then workflow_id. If we generate a link to the Rule, the FE will redirect it to the workflow link if the new UI feature flag is on. Otherwise the workflow is single-written and we can only generate link to the workflow.

Builds on #106048 (last one to remove the flag for issue alerts)

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jan 10, 2026
@cathteng cathteng force-pushed the cathy/aci/workflow-rule-action-dispatch branch from 85f9312 to 7e94a89 Compare January 10, 2026 00:22
@cathteng cathteng force-pushed the cathy/aci/workflow-rule-action-dispatch branch from 13bf816 to 57234f9 Compare January 10, 2026 01:24
@cathteng cathteng marked this pull request as ready for review January 10, 2026 01:48
@cathteng cathteng requested review from a team as code owners January 10, 2026 01:48
workflow_id=workflow_id,
)

rule = Rule.objects.get(id=alert_rule_workflow.rule_id)

This comment was marked as outdated.

Copy link
Member Author

Choose a reason for hiding this comment

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

It will actually raise Rule.DoesNotExist


# attempt to find legacy_rule_id from the alert rule workflow
try:
alert_rule_workflow = AlertRuleWorkflow.objects.get(
Copy link
Member

Choose a reason for hiding this comment

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

bah, shame we're not using foreign keys or we could just do something like Rule.objects.filter(alertruleworkflow__workflow_id=workflow_id).first().

I still think single expr and first might be nice here, eg:

rule = Rule.objects.filter(
      id__in=AlertRuleWorkflow.objects.filter(workflow_id=workflow_id).values('rule_id')
 ).first()
if rule:
    label = ..
    rule_id = ...

Base automatically changed from cathy/aci/workflow-rule-integrations to cathy/aci/workflow-rule-in-digests January 12, 2026 23:36
@cathteng cathteng requested a review from a team as a code owner January 12, 2026 23:36
Base automatically changed from cathy/aci/workflow-rule-in-digests to master January 13, 2026 18:31
@cathteng cathteng force-pushed the cathy/aci/workflow-rule-action-dispatch branch from 3de4aa0 to 146639e Compare January 13, 2026 18:36
Comment on lines +206 to +212
alert_rule_workflow = AlertRuleWorkflow.objects.filter(
workflow_id=workflow_id,
).first()
if alert_rule_workflow:
try:
rule = Rule.objects.get(id=alert_rule_workflow.rule_id)
label = rule.label
label = Rule.objects.get(id=alert_rule_workflow.rule_id).label
rule_id = alert_rule_workflow.rule_id
Copy link

Choose a reason for hiding this comment

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

Bug: The query for AlertRuleWorkflow can fetch a metric alert where rule_id is None, causing an unhandled ValueError when Rule.objects.get(id=None) is called.
Severity: CRITICAL

Suggested Fix

Modify the AlertRuleWorkflow query to explicitly filter for entries related to issue alerts by adding rule_id__isnull=False. This ensures that the query only returns workflows that have a valid rule_id.

alert_rule_workflow = AlertRuleWorkflow.objects.filter(
    workflow_id=workflow_id,
    rule_id__isnull=False,
).first()
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/notifications/notification_action/types.py#L206-L212

Potential issue: The query for an `AlertRuleWorkflow` using
`.filter(workflow_id=workflow_id).first()` is non-deterministic. If a workflow is
associated with both an issue alert (`rule_id` is set) and a metric alert
(`alert_rule_id` is set), this query might return the metric alert entry where `rule_id`
is `None`. The subsequent call, `Rule.objects.get(id=alert_rule_workflow.rule_id)`, will
then execute as `Rule.objects.get(id=None)`, raising a `ValueError`. This exception is
not caught by the `except Rule.DoesNotExist` block, leading to an unhandled error.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Member Author

Choose a reason for hiding this comment

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

This raises Rule.DoesNotExist which is caught

@cathteng cathteng merged commit 9454a90 into master Jan 13, 2026
66 checks passed
@cathteng cathteng deleted the cathy/aci/workflow-rule-action-dispatch branch January 13, 2026 18:59
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