Skip to content

Commit b4bb9a8

Browse files
authored
fix(aci): Add support for an empty conditionGroup in the API for the Error detector (#112641)
# Description Fixes: https://linear.app/getsentry/issue/ISWF-2357/saving-error-monitor-after-creating-alert-fails <img width="1080" height="394" alt="Screenshot 2026-04-09 at 4 18 21 PM" src="https://github.com/user-attachments/assets/6e5d899e-5aef-486c-ac19-da6bebfb620d" /> The issue seems like that the validator for ErrorDetectors was throwing because it has an empty data condition group; this should be okay and makes sense in our UI to provide as a default. Rather than updating the UI to not send the field, this PR will allow the `{}` for the condition group.
1 parent 2464008 commit b4bb9a8

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def update(self, instance: Detector, validated_data: dict[str, Any]) -> Detector
222222
validated_data.pop("owner")
223223
)
224224

225-
if "condition_group" in validated_data:
225+
if "condition_group" in validated_data and validated_data.get("condition_group"):
226226
condition_group = validated_data.pop("condition_group")
227227
data_conditions: list[DataConditionType] = condition_group.get("conditions")
228228

src/sentry/workflow_engine/endpoints/validators/error_detector.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@
1616
class ErrorDetectorValidator(BaseDetectorTypeValidator):
1717
data_source_required = False
1818

19+
# TODO - Update the Error Detector to store grouping rules in the DataCondition
20+
condition_group = serializers.DictField(
21+
required=False,
22+
allow_null=True,
23+
) # type: ignore[assignment] # Intentionally overrides nested serializer to accept empty dicts
24+
1925
fingerprinting_rules = serializers.CharField(required=False, allow_blank=True, allow_null=True)
26+
2027
resolve_age = EmptyIntegerField(
2128
required=False,
2229
allow_null=True,
@@ -31,11 +38,12 @@ def validate_type(self, value: str) -> builtins.type[GroupType]:
3138
return type
3239

3340
def validate_condition_group(self, value: Any) -> Any:
34-
if value is not None:
41+
if value:
3542
raise serializers.ValidationError(
3643
"Condition group is not supported for error detectors"
3744
)
38-
return value
45+
46+
return None
3947

4048
def validate_name(self, value: Any) -> str:
4149
# if name is different from existing, raise an error

tests/sentry/workflow_engine/detectors/test_error_detector.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ def test_invalid_condition_group(self) -> None:
8282
)
8383
]
8484

85+
def test_valid_condition_group(self) -> None:
86+
data = {
87+
**self.valid_data,
88+
"condition_group": {},
89+
}
90+
validator = ErrorDetectorValidator(data=data, context=self.context)
91+
assert validator.is_valid()
92+
8593
def test_update_existing_with_valid_data(self) -> None:
8694
user = self.create_user()
8795
self.create_member(organization=self.project.organization, user=user)

0 commit comments

Comments
 (0)