Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/sentry/incidents/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions tests/sentry/incidents/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 == []
Loading