Skip to content

Conversation

@mifu67
Copy link
Contributor

@mifu67 mifu67 commented Nov 24, 2025

Should probably be merged before #103937. If an open period comes in without a corresponding entry in the IGOP table, create a fake ID for the incident and pass it to the frontend, where it will be used for redirect logic. Do the same for detector IDs that don't have entries in the AlertRuleDetector table.

@mifu67 mifu67 requested a review from a team November 24, 2025 23:05
@mifu67 mifu67 requested review from a team as code owners November 24, 2025 23:05
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 24, 2025
Comment on lines 239 to 246
if alert_rule_id is None:
raise ValueError("Alert rule id not found when querying for AlertRuleDetector")
except AlertRuleDetector.DoesNotExist:
raise ValueError("Alert rule detector not found when querying for AlertRuleDetector")
# the corresponding metric detector was not dual written
alert_rule_id = get_fake_id_from_object_id(alert_context.action_identifier_id)

workflow_engine_params = title_link_params.copy()

Copy link

Choose a reason for hiding this comment

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

Bug: AlertRuleDetector.objects.values_list(...).get() returns None for issue rule detectors, causing ValueError instead of graceful fallback.
Severity: HIGH | Confidence: High

🔍 Detailed Analysis

The code in metric_alerts.py attempts to retrieve alert_rule_id from AlertRuleDetector. If an AlertRuleDetector exists but has rule_id set and alert_rule_id is NULL (indicating it's linked to an issue rule detector), the .get() call will return None. The subsequent if alert_rule_id is None: check then raises a ValueError, preventing the intended graceful fallback to a fake ID. This occurs when a detector is misconfigured or partially migrated, leading to an unexpected crash instead of a graceful fallback.

💡 Suggested Fix

Modify the code to handle alert_rule_id being None when rule_id is present, allowing the graceful fallback mechanism to activate.

🤖 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/integrations/metric_alerts.py#L239-L246

Potential issue: The code in `metric_alerts.py` attempts to retrieve `alert_rule_id`
from `AlertRuleDetector`. If an `AlertRuleDetector` exists but has `rule_id` set and
`alert_rule_id` is `NULL` (indicating it's linked to an issue rule detector), the
`.get()` call will return `None`. The subsequent `if alert_rule_id is None:` check then
raises a `ValueError`, preventing the intended graceful fallback to a fake ID. This
occurs when a detector is misconfigured or partially migrated, leading to an unexpected
crash instead of a graceful fallback.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 3334006

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Issue alerts don't go through this code. Silly bot.

Comment on lines 251 to +256
workflow_engine_params["alert"] = str(open_period_incident.incident_identifier)
except IncidentGroupOpenPeriod.DoesNotExist as e:
sentry_sdk.capture_exception(e)
except IncidentGroupOpenPeriod.DoesNotExist:
# the corresponding metric detector was not dual written
workflow_engine_params["alert"] = str(
get_fake_id_from_object_id(metric_issue_context.open_period_identifier)
)
Copy link

Choose a reason for hiding this comment

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

Bug: API endpoints fail with 404 for metric alert links containing fake IDs due to missing conversion logic.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

Fake IDs generated for metric alerts are embedded in URLs and passed to API endpoints. The IncidentEndpoint.convert_args() method directly queries the database using Incident.objects.get(organization=organization, identifier=incident_identifier). Since fake IDs (e.g., original_id + 10^9) do not match any real Incident.identifier values, this lookup fails, raising Incident.DoesNotExist and resulting in a 404 error. There is no conversion logic in the API endpoint to transform fake IDs back to real IDs.

💡 Suggested Fix

Implement logic in IncidentEndpoint.convert_args() or a preceding layer to convert fake IDs back to real IDs using get_object_id_from_fake_id() before performing database lookups.

🤖 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/integrations/metric_alerts.py#L251-L256

Potential issue: Fake IDs generated for metric alerts are embedded in URLs and passed to
API endpoints. The `IncidentEndpoint.convert_args()` method directly queries the
database using `Incident.objects.get(organization=organization,
identifier=incident_identifier)`. Since fake IDs (e.g., `original_id + 10^9`) do not
match any real `Incident.identifier` values, this lookup fails, raising
`Incident.DoesNotExist` and resulting in a 404 error. There is no conversion logic in
the API endpoint to transform fake IDs back to real IDs.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 3334006

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines +164 to +167
assert (
data["title_link"]
== f"http://testserver/organizations/baz/alerts/rules/details/{fake_alert_rule_id}/?alert={fake_incident_identifier}&referrer={referrer}&detection_type=static&notification_uuid={notification_uuid}"
)
Copy link
Member

Choose a reason for hiding this comment

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

Forgive me if I missed some context, but will users actually see these links? They won't work, right? Or will we be sending different links for single written detectors that work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, they will see these links. Mia has worked on redirects, so they will link to the monitor.

@mifu67 mifu67 requested review from a team and ceorourke November 25, 2025 18:23
@mifu67 mifu67 merged commit 8420950 into master Nov 25, 2025
68 checks passed
@mifu67 mifu67 deleted the mifu67/aci/support-no-igop-links branch November 25, 2025 18:25
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