feat(notifications): Add notification data and renderer for metric alerts#111674
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:54src/sentry/notifications/platform/slack/renderers/metric_alert.py:74src/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
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
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
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
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
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.