From 1cb553521e803390db0470a0c92a1a0a2f4a6059 Mon Sep 17 00:00:00 2001 From: Mia Hsu Date: Fri, 31 Oct 2025 11:45:07 -0700 Subject: [PATCH] feat(aci): add description field to detector validator --- .../endpoints/validators/base/detector.py | 6 ++++++ .../test_organization_detector_details.py | 18 ++++++++++++++++++ .../test_organization_detector_index.py | 13 +++++++++++++ 3 files changed, 37 insertions(+) diff --git a/src/sentry/workflow_engine/endpoints/validators/base/detector.py b/src/sentry/workflow_engine/endpoints/validators/base/detector.py index 41ad262d86883b..6f3e0af9137b1b 100644 --- a/src/sentry/workflow_engine/endpoints/validators/base/detector.py +++ b/src/sentry/workflow_engine/endpoints/validators/base/detector.py @@ -47,6 +47,7 @@ class BaseDetectorTypeValidator(CamelSnakeSerializer): type = serializers.CharField() config = serializers.JSONField(default=dict) owner = ActorField(required=False, allow_null=True) + description = serializers.CharField(required=False, allow_null=True, allow_blank=True) enabled = serializers.BooleanField(required=False) condition_group = BaseDataConditionGroupValidator(required=False) @@ -97,6 +98,10 @@ def update(self, instance: Detector, validated_data: dict[str, Any]): if "name" in validated_data: instance.name = validated_data.get("name", instance.name) + # Handle description field update + if "description" in validated_data: + instance.description = validated_data.get("description", instance.description) + # Handle enable/disable detector if "enabled" in validated_data: enabled = validated_data.get("enabled") @@ -180,6 +185,7 @@ def create(self, validated_data): detector = Detector( project_id=self.context["project"].id, name=validated_data["name"], + description=validated_data.get("description"), workflow_condition_group=condition_group, type=validated_data["type"].slug, config=validated_data.get("config", {}), diff --git a/tests/sentry/workflow_engine/endpoints/test_organization_detector_details.py b/tests/sentry/workflow_engine/endpoints/test_organization_detector_details.py index 8675b13cb7e497..5df30ee19f9312 100644 --- a/tests/sentry/workflow_engine/endpoints/test_organization_detector_details.py +++ b/tests/sentry/workflow_engine/endpoints/test_organization_detector_details.py @@ -230,6 +230,24 @@ def test_update(self, mock_schedule_update_project_config: mock.MagicMock) -> No self.assert_snuba_query_updated(snuba_query) mock_schedule_update_project_config.assert_called_once_with(detector) + def test_update_description(self) -> None: + assert self.detector.description is None + + data = { + "description": "New description for the detector", + } + + with self.tasks(): + self.get_success_response( + self.organization.slug, + self.detector.id, + **data, + status_code=200, + ) + + self.detector.refresh_from_db() + assert self.detector.description == "New description for the detector" + def test_update_add_data_condition(self) -> None: """ Test that we can add an additional data condition diff --git a/tests/sentry/workflow_engine/endpoints/test_organization_detector_index.py b/tests/sentry/workflow_engine/endpoints/test_organization_detector_index.py index 27b264947148b6..d43fd3226a0905 100644 --- a/tests/sentry/workflow_engine/endpoints/test_organization_detector_index.py +++ b/tests/sentry/workflow_engine/endpoints/test_organization_detector_index.py @@ -841,6 +841,7 @@ def test_valid_creation( assert detector.name == "Test Detector" assert detector.type == MetricIssue.slug assert detector.project_id == self.project.id + assert detector.description is None # Verify data source data_source = DataSource.objects.get(detector=detector) @@ -890,6 +891,18 @@ def test_valid_creation( ) mock_schedule_update_project_config.assert_called_once_with(detector) + def test_creation_with_description(self) -> None: + data = {**self.valid_data, "description": "This is a test metric detector"} + with self.tasks(): + response = self.get_success_response( + self.organization.slug, + **data, + status_code=201, + ) + + detector = Detector.objects.get(id=response.data["id"]) + assert detector.description == "This is a test metric detector" + def test_invalid_workflow_ids(self) -> None: # Workflow doesn't exist at all data = {**self.valid_data, "workflowIds": [999999]}