Skip to content

fix(np): Updates issue notification data factory to select correct handler class#112892

Open
GabeVillalobos wants to merge 1 commit intomasterfrom
gv/fix-handler-selection
Open

fix(np): Updates issue notification data factory to select correct handler class#112892
GabeVillalobos wants to merge 1 commit intomasterfrom
gv/fix-handler-selection

Conversation

@GabeVillalobos
Copy link
Copy Markdown
Member

No description provided.

@GabeVillalobos GabeVillalobos requested review from a team as code owners April 14, 2026 00:01
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 14, 2026
Comment on lines +120 to +122
handler = issue_alert_handler_registry.get(action.type)
if handler is None:
raise ValueError(f"No issue alert handler found for action type: {action.type}")
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.

Dead code: None check never triggers because Registry.get() raises exception instead

The issue_alert_handler_registry.get() method raises NoRegistrationExistsError when the key is not found (see sentry/utils/registry.py lines 45-48) - it never returns None. The if handler is None: check on line 121-122 is dead code and the ValueError is never raised. If an unregistered action type is passed, NoRegistrationExistsError will propagate up unhandled, unlike the sibling functions execute_via_issue_alert_handler and execute_via_metric_alert_handler which properly catch this exception.

Verification

Read sentry/utils/registry.py to confirm Registry.get() raises NoRegistrationExistsError (lines 46-47) instead of returning None. Verified sibling functions in the same file (lines 75-84, 97-106) properly handle this with try/except blocks.

Identified by Warden sentry-backend-bugs · KYW-DJB

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 1 potential issue.

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 b7a43e2. Configure here.

rule_instance = BaseIssueAlertHandler.create_rule_instance_from_action(
handler = issue_alert_handler_registry.get(action.type)
if handler is None:
raise ValueError(f"No issue alert handler found for action type: {action.type}")
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.

Dead code: registry.get() raises instead of returning None

Medium Severity

issue_alert_handler_registry.get(action.type) raises NoRegistrationExistsError when the key isn't found — it never returns None. The if handler is None guard is dead code and the intended ValueError will never be raised. Instead, a NoRegistrationExistsError will propagate, which is a different exception type than what callers might expect. Other call sites (e.g., execute_via_issue_alert_handler) correctly handle this by catching NoRegistrationExistsError.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b7a43e2. Configure here.

Comment on lines +121 to +122
if handler is None:
raise ValueError(f"No issue alert handler found for action type: {action.type}")
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: The issue_alert_handler_registry.get() call raises NoRegistrationExistsError for missing keys, but the code incorrectly checks for None, leading to an unhandled exception.
Severity: MEDIUM

Suggested Fix

Replace the if handler is None check with a try...except NoRegistrationExistsError block around the issue_alert_handler_registry.get(action.type) call. In the except block, raise the intended ValueError. This aligns with the error handling pattern used elsewhere in the file for registry 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/notifications/notification_action/utils.py#L121-L122

Potential issue: In the `issue_notification_data_factory` function, the code retrieves a
handler using `issue_alert_handler_registry.get(action.type)` and then checks if the
result is `None`. However, the `get` method of the registry raises a
`NoRegistrationExistsError` if the key is not found; it never returns `None`.
Consequently, the `if handler is None` block is dead code. If an unregistered
`action.type` is provided, an unhandled `NoRegistrationExistsError` will propagate
instead of the intended `ValueError`, breaking the function's error handling contract.

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

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.

1 participant