From cb785cd1ecb09920b04e5212bd05a0d1283dd82c Mon Sep 17 00:00:00 2001 From: Cathy Teng Date: Wed, 19 Nov 2025 16:14:23 -0800 Subject: [PATCH] create DetectorGroup with null detector if we can't find event --- .../0099_backfill_metric_issue_detectorgroup.py | 9 ++++++++- .../test_0099_backfill_metric_issue_detectorgroup.py | 7 ++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/sentry/workflow_engine/migrations/0099_backfill_metric_issue_detectorgroup.py b/src/sentry/workflow_engine/migrations/0099_backfill_metric_issue_detectorgroup.py index 497e88a0638c67..6ef66917d4ddbd 100644 --- a/src/sentry/workflow_engine/migrations/0099_backfill_metric_issue_detectorgroup.py +++ b/src/sentry/workflow_engine/migrations/0099_backfill_metric_issue_detectorgroup.py @@ -82,7 +82,14 @@ def backfill_metric_issue_detectorgroup( # figure out the detector latest_event = get_oldest_or_latest_event(group, EventOrdering.LATEST) if not latest_event: - logger.info("No latest event found for group", extra={"group_id": group.id}) + DetectorGroup.objects.create( + group_id=group.id, + detector_id=None, + ) + logger.info( + "No latest event found for group, creating DetectorGroup with null detector", + extra={"group_id": group.id}, + ) continue occurrence = latest_event.occurrence diff --git a/tests/sentry/workflow_engine/migrations/test_0099_backfill_metric_issue_detectorgroup.py b/tests/sentry/workflow_engine/migrations/test_0099_backfill_metric_issue_detectorgroup.py index 3412158aaf2462..69aab62ad0513d 100644 --- a/tests/sentry/workflow_engine/migrations/test_0099_backfill_metric_issue_detectorgroup.py +++ b/tests/sentry/workflow_engine/migrations/test_0099_backfill_metric_issue_detectorgroup.py @@ -86,9 +86,10 @@ def test_migration(self) -> None: group=self.metric_issue_deleted_detector, detector=None ).exists() - assert not DetectorGroup.objects.filter( - group=self.metric_issue_no_occurrence - ).exists() # does not exist because we should figure out what to do with this + assert DetectorGroup.objects.filter( + group=self.metric_issue_no_occurrence, + detector=None, + ).exists() assert DetectorGroup.objects.filter( group=self.metric_issue_existing_detectorgroup, detector=self.detector2