diff --git a/src/sentry/incidents/logic.py b/src/sentry/incidents/logic.py index dce91c68562e..7cf3d116720f 100644 --- a/src/sentry/incidents/logic.py +++ b/src/sentry/incidents/logic.py @@ -1995,7 +1995,9 @@ def get_filtered_actions( alert_rule_data: Mapping[str, Any], action_type: ActionService, ) -> list[dict[str, Any]]: - def is_included(action: Mapping[str, Any]) -> bool: + def is_included(action: Mapping[str, Any] | None) -> bool: + if action is None: + return False type_slug = action.get("type") if type_slug is None or not isinstance(type_slug, str): return False diff --git a/tests/sentry/incidents/test_logic.py b/tests/sentry/incidents/test_logic.py index b7f1bf395b5f..b8e78aa0a2b0 100644 --- a/tests/sentry/incidents/test_logic.py +++ b/tests/sentry/incidents/test_logic.py @@ -46,6 +46,7 @@ get_actions_for_trigger, get_alert_resolution, get_available_action_integrations_for_org, + get_filtered_actions, get_metric_issue_aggregates, get_triggers_for_alert_rule, snapshot_alert_rule, @@ -3707,3 +3708,39 @@ def test_crazy_low_range(self) -> None: time_window = -5 result = get_alert_resolution(time_window, self.organization) assert result == timedelta(minutes=DEFAULT_ALERT_RULE_RESOLUTION) + + +class TestGetFilteredActions(TestCase): + def test_none_action_in_trigger_actions(self) -> None: + # Regression test: None entries in trigger actions must not raise AttributeError + alert_rule_data: dict = { + "triggers": [ + { + "actions": [ + None, + {"type": "sentry_app"}, + ] + } + ] + } + from sentry.incidents.models.alert_rule import AlertRuleTriggerAction + + result = get_filtered_actions( + alert_rule_data, AlertRuleTriggerAction.Type.SENTRY_APP + ) + assert isinstance(result, list) + + def test_empty_actions(self) -> None: + alert_rule_data: dict = {"triggers": [{"actions": []}]} + from sentry.incidents.models.alert_rule import AlertRuleTriggerAction + + result = get_filtered_actions( + alert_rule_data, AlertRuleTriggerAction.Type.SENTRY_APP + ) + assert result == [] + + def test_no_triggers(self) -> None: + from sentry.incidents.models.alert_rule import AlertRuleTriggerAction + + result = get_filtered_actions({}, AlertRuleTriggerAction.Type.SENTRY_APP) + assert result == []