From e13d00e0c10a5dde777dd4335017f660e76511ad Mon Sep 17 00:00:00 2001 From: Dan Fuller Date: Fri, 18 Oct 2024 16:09:41 -0700 Subject: [PATCH] back to coalesce --- migrations_lockfile.txt | 2 +- ...ique_gruop.py => 0010_detector_state_unique_group.py} | 9 ++++++--- src/sentry/workflow_engine/models/detector_state.py | 6 ++++-- 3 files changed, 11 insertions(+), 6 deletions(-) rename src/sentry/workflow_engine/migrations/{0010_detector_state_unique_gruop.py => 0010_detector_state_unique_group.py} (84%) diff --git a/migrations_lockfile.txt b/migrations_lockfile.txt index 281d6beed10e1e..f8d02cc06e943a 100644 --- a/migrations_lockfile.txt +++ b/migrations_lockfile.txt @@ -13,4 +13,4 @@ replays: 0004_index_together sentry: 0777_add_related_name_to_dashboard_permissions social_auth: 0002_default_auto_field uptime: 0017_unique_on_timeout -workflow_engine: 0010_detector_state_unique_gruop +workflow_engine: 0010_detector_state_unique_group diff --git a/src/sentry/workflow_engine/migrations/0010_detector_state_unique_gruop.py b/src/sentry/workflow_engine/migrations/0010_detector_state_unique_group.py similarity index 84% rename from src/sentry/workflow_engine/migrations/0010_detector_state_unique_gruop.py rename to src/sentry/workflow_engine/migrations/0010_detector_state_unique_group.py index 2e22d6623f7762..e6ea252b58f062 100644 --- a/src/sentry/workflow_engine/migrations/0010_detector_state_unique_gruop.py +++ b/src/sentry/workflow_engine/migrations/0010_detector_state_unique_group.py @@ -1,5 +1,6 @@ -# Generated by Django 5.1.1 on 2024-10-18 23:02 +# Generated by Django 5.1.1 on 2024-10-18 23:09 +import django.db.models.functions.comparison from django.db import migrations, models from sentry.new_migrations.migrations import CheckedMigration @@ -28,9 +29,11 @@ class Migration(CheckedMigration): migrations.AddConstraint( model_name="detectorstate", constraint=models.UniqueConstraint( - fields=("detector", "detector_group_key"), + models.F("detector"), + django.db.models.functions.comparison.Coalesce( + "detector_group_key", models.Value("") + ), name="detector_state_unique_group_key", - nulls_distinct=False, ), ), ] diff --git a/src/sentry/workflow_engine/models/detector_state.py b/src/sentry/workflow_engine/models/detector_state.py index 40a65e2faefc25..42a09cb4b244ff 100644 --- a/src/sentry/workflow_engine/models/detector_state.py +++ b/src/sentry/workflow_engine/models/detector_state.py @@ -1,6 +1,8 @@ from enum import StrEnum from django.db import models +from django.db.models import F, Value +from django.db.models.functions import Coalesce from sentry.backup.scopes import RelocationScope from sentry.db.models import DefaultFieldsModel, FlexibleForeignKey, region_silo_model @@ -29,8 +31,8 @@ class DetectorState(DefaultFieldsModel): class Meta: constraints = [ models.UniqueConstraint( - fields=["detector", "detector_group_key"], - nulls_distinct=False, + F("detector"), + Coalesce("detector_group_key", Value("")), name="detector_state_unique_group_key", ), ]