fix(np): Updates issue notification data factory to select correct handler class#112892
fix(np): Updates issue notification data factory to select correct handler class#112892GabeVillalobos wants to merge 1 commit intomasterfrom
Conversation
| 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}") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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}") |
There was a problem hiding this comment.
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.
Reviewed by Cursor Bugbot for commit b7a43e2. Configure here.
| if handler is None: | ||
| raise ValueError(f"No issue alert handler found for action type: {action.type}") |
There was a problem hiding this comment.
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.


No description provided.