Skip to content

Commit e9b4340

Browse files
ameliahsujjbayer
authored andcommitted
feat(aci): add description field to detector validator (#102505)
added `description` to the detector validator so users can add create/update detector descriptions
1 parent 59e1e9c commit e9b4340

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/sentry/workflow_engine/endpoints/validators/base/detector.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class BaseDetectorTypeValidator(CamelSnakeSerializer):
4747
type = serializers.CharField()
4848
config = serializers.JSONField(default=dict)
4949
owner = ActorField(required=False, allow_null=True)
50+
description = serializers.CharField(required=False, allow_null=True, allow_blank=True)
5051
enabled = serializers.BooleanField(required=False)
5152
condition_group = BaseDataConditionGroupValidator(required=False)
5253

@@ -97,6 +98,10 @@ def update(self, instance: Detector, validated_data: dict[str, Any]):
9798
if "name" in validated_data:
9899
instance.name = validated_data.get("name", instance.name)
99100

101+
# Handle description field update
102+
if "description" in validated_data:
103+
instance.description = validated_data.get("description", instance.description)
104+
100105
# Handle enable/disable detector
101106
if "enabled" in validated_data:
102107
enabled = validated_data.get("enabled")
@@ -182,6 +187,7 @@ def create(self, validated_data):
182187
detector = Detector(
183188
project_id=self.context["project"].id,
184189
name=validated_data["name"],
190+
description=validated_data.get("description"),
185191
workflow_condition_group=condition_group,
186192
type=validated_data["type"].slug,
187193
config=validated_data.get("config", {}),

tests/sentry/workflow_engine/endpoints/test_organization_detector_details.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,24 @@ def test_update(self, mock_schedule_update_project_config: mock.MagicMock) -> No
234234
self.assert_snuba_query_updated(snuba_query)
235235
mock_schedule_update_project_config.assert_called_once_with(detector)
236236

237+
def test_update_description(self) -> None:
238+
assert self.detector.description is None
239+
240+
data = {
241+
"description": "New description for the detector",
242+
}
243+
244+
with self.tasks():
245+
self.get_success_response(
246+
self.organization.slug,
247+
self.detector.id,
248+
**data,
249+
status_code=200,
250+
)
251+
252+
self.detector.refresh_from_db()
253+
assert self.detector.description == "New description for the detector"
254+
237255
def test_update_add_data_condition(self) -> None:
238256
"""
239257
Test that we can add an additional data condition

tests/sentry/workflow_engine/endpoints/test_organization_detector_index.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,7 @@ def test_valid_creation(
841841
assert detector.name == "Test Detector"
842842
assert detector.type == MetricIssue.slug
843843
assert detector.project_id == self.project.id
844+
assert detector.description is None
844845

845846
# Verify data source
846847
data_source = DataSource.objects.get(detector=detector)
@@ -890,6 +891,18 @@ def test_valid_creation(
890891
)
891892
mock_schedule_update_project_config.assert_called_once_with(detector)
892893

894+
def test_creation_with_description(self) -> None:
895+
data = {**self.valid_data, "description": "This is a test metric detector"}
896+
with self.tasks():
897+
response = self.get_success_response(
898+
self.organization.slug,
899+
**data,
900+
status_code=201,
901+
)
902+
903+
detector = Detector.objects.get(id=response.data["id"])
904+
assert detector.description == "This is a test metric detector"
905+
893906
def test_invalid_workflow_ids(self) -> None:
894907
# Workflow doesn't exist at all
895908
data = {**self.valid_data, "workflowIds": [999999]}

0 commit comments

Comments
 (0)