Skip to content

feat(notifications): Add notification data and renderer for metric alerts#111674

Merged
Christinarlong merged 16 commits into
masterfrom
crl/meetric-alert-data
Mar 30, 2026
Merged

feat(notifications): Add notification data and renderer for metric alerts#111674
Christinarlong merged 16 commits into
masterfrom
crl/meetric-alert-data

typing

5452b67
Select commit
Loading
Failed to load commit list.
@sentry/warden / warden completed Mar 30, 2026 in 3m 23s

2 issues

Medium

Activity.DoesNotExist not handled in async notification renderer - `src/sentry/notifications/platform/slack/renderers/metric_alert.py:53`

The Activity.objects.get(id=data.activity_id) call on line 53 does not handle Activity.DoesNotExist. Since this renderer runs in an async Celery task, activities can be deleted between notification creation and task execution. Activities can be deleted through data retention, cascade deletes from groups, or manual cleanup.

Also found at:

  • src/sentry/notifications/platform/slack/renderers/metric_alert.py:54
  • src/sentry/notifications/platform/slack/renderers/metric_alert.py:74
  • src/sentry/notifications/platform/slack/renderers/metric_alert.py:75
Enum conversions in to_alert_context may raise unhandled ValueError - `src/sentry/notifications/platform/templates/metric_alert.py:49-56`

The to_alert_context() method converts serialized integer/string values to enum types (AlertRuleDetectionType, AlertRuleThresholdType, AnomalyDetectionThresholdType) without try/except for ValueError. If the serialized notification data contains invalid values (from data corruption, schema changes, or stale persisted data), these conversions will raise ValueError and crash the notification path. This matches the pattern from SENTRY-494A where alert actions crash at scale.

2 skills analyzed
Skill Findings Duration Cost
sentry-security 0 1m 39s $2.06
sentry-backend-bugs 2 3m 11s $1.74

Duration: 4m 50s · Tokens: 2.2M in / 29.3k out · Cost: $3.84 (+extraction: $0.02, +merge: $0.00, +fix_gate: $0.00, +dedup: $0.02)