diff --git a/src/sentry/incidents/endpoints/serializers/alert_rule.py b/src/sentry/incidents/endpoints/serializers/alert_rule.py index a91a628812f7cd..cb9e4ac0ed94d7 100644 --- a/src/sentry/incidents/endpoints/serializers/alert_rule.py +++ b/src/sentry/incidents/endpoints/serializers/alert_rule.py @@ -175,9 +175,9 @@ def get_attrs( order_by=F("date_added").desc(), ) ) - activations = alert_activations_ranked.filter(alert_rule__in=item_list, rank__lte=10) + activations_qs = alert_activations_ranked.filter(alert_rule__in=item_list, rank__lte=10) activations_by_alert_rule_id = defaultdict(list) - for activation in activations: + for activation in activations_qs: activations_by_alert_rule_id[activation.alert_rule_id].append(activation) alert_rule_projects = set() diff --git a/src/sentry/incidents/endpoints/serializers/alert_rule_trigger.py b/src/sentry/incidents/endpoints/serializers/alert_rule_trigger.py index c7bb264383077f..c188c507c94349 100644 --- a/src/sentry/incidents/endpoints/serializers/alert_rule_trigger.py +++ b/src/sentry/incidents/endpoints/serializers/alert_rule_trigger.py @@ -50,12 +50,12 @@ def serialize(self, obj, attrs, user, **kwargs): class DetailedAlertRuleTriggerSerializer(AlertRuleTriggerSerializer): def get_attrs(self, item_list, user, **kwargs): triggers = {item.id: item for item in item_list} - result: DefaultDict[str, dict[str, list[str]]] = defaultdict(dict) + result: dict[str, dict[str, list[str]]] = defaultdict(lambda: defaultdict(list)) for trigger_id, project_slug in AlertRuleTriggerExclusion.objects.filter( alert_rule_trigger__in=item_list ).values_list("alert_rule_trigger_id", "query_subscription__project__slug"): - exclusions = result[triggers[trigger_id]].setdefault("excludedProjects", []) - exclusions.append(project_slug) + if project_slug is not None: + result[triggers[trigger_id]]["excludedProjects"].append(project_slug) return result def serialize(self, obj, attrs, user, **kwargs):