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: sentry-backend-bugs completed Mar 30, 2026 in 3m 16s

2 issues

sentry-backend-bugs: Found 2 issues (2 medium)

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.


Duration: 3m 11s · Tokens: 1.1M in / 15.6k out · Cost: $1.76 (+extraction: $0.02, +merge: $0.00, +fix_gate: $0.00)

Annotations

Check warning on line 53 in src/sentry/notifications/platform/slack/renderers/metric_alert.py

See this annotation in the file changed.

@sentry-warden sentry-warden / warden: sentry-backend-bugs

Activity.DoesNotExist not handled in async notification renderer

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.

Check warning on line 54 in src/sentry/notifications/platform/slack/renderers/metric_alert.py

See this annotation in the file changed.

@sentry-warden sentry-warden / warden: sentry-backend-bugs

[87C-X5B] Activity.DoesNotExist not handled in async notification renderer (additional location)

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.

Check warning on line 74 in src/sentry/notifications/platform/slack/renderers/metric_alert.py

See this annotation in the file changed.

@sentry-warden sentry-warden / warden: sentry-backend-bugs

[87C-X5B] Activity.DoesNotExist not handled in async notification renderer (additional location)

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.

Check warning on line 75 in src/sentry/notifications/platform/slack/renderers/metric_alert.py

See this annotation in the file changed.

@sentry-warden sentry-warden / warden: sentry-backend-bugs

[87C-X5B] Activity.DoesNotExist not handled in async notification renderer (additional location)

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.

Check warning on line 56 in src/sentry/notifications/platform/templates/metric_alert.py

See this annotation in the file changed.

@sentry-warden sentry-warden / warden: sentry-backend-bugs

Enum conversions in to_alert_context may raise unhandled ValueError

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.