Skip to content

Commit a7d955c

Browse files
committed
rename type to group and fix serializer
1 parent bd50ca9 commit a7d955c

File tree

3 files changed

+44
-39
lines changed

3 files changed

+44
-39
lines changed

src/sentry/workflow_engine/endpoints/organization_data_condition_index.py

+13-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import NotRequired, TypedDict
2-
31
from drf_spectacular.utils import extend_schema
42
from rest_framework import serializers
53

@@ -17,19 +15,15 @@
1715
)
1816
from sentry.apidocs.parameters import GlobalParams
1917
from sentry.apidocs.utils import inline_sentry_response_serializer
20-
from sentry.workflow_engine.endpoints.serializers import DataConditionHandlerSerializer
18+
from sentry.workflow_engine.endpoints.serializers import (
19+
DataConditionHandlerResponse,
20+
DataConditionHandlerSerializer,
21+
)
2122
from sentry.workflow_engine.models.data_condition import LEGACY_CONDITIONS
2223
from sentry.workflow_engine.registry import condition_handler_registry
2324
from sentry.workflow_engine.types import DataConditionHandler
2425

2526

26-
class DataConditionHandlerResponse(TypedDict):
27-
condition_id: str
28-
type: str
29-
filter_group: NotRequired[str]
30-
comparison_json_schema: dict
31-
32-
3327
@region_silo_endpoint
3428
class OrganizationDataConditionIndexEndpoint(OrganizationEndpoint):
3529
publish_status = {
@@ -56,22 +50,23 @@ def get(self, request, organization):
5650
"""
5751
Returns a list of data conditions for a given org
5852
"""
59-
type = request.GET.get("type")
53+
group = request.GET.get("group")
6054
try:
61-
DataConditionHandler.Type(type)
55+
DataConditionHandler.Group(group)
6256
except ValueError:
6357
raise serializers.ValidationError("Invalid group")
6458

6559
data_conditions = []
6660

6761
for condition, handler in condition_handler_registry.registrations.items():
68-
if condition not in LEGACY_CONDITIONS and handler.type == type:
69-
condition_json = {"condition_id": condition}
70-
71-
condition_json.update(
72-
serialize(handler, request.user, DataConditionHandlerSerializer())
62+
if condition not in LEGACY_CONDITIONS and handler.group == group:
63+
serialized = serialize(
64+
handler,
65+
request.user,
66+
DataConditionHandlerSerializer(),
67+
condition_type=condition,
7368
)
74-
data_conditions.append(condition_json)
69+
data_conditions.append(serialized)
7570

7671
return self.paginate(
7772
request=request,

src/sentry/workflow_engine/endpoints/serializers.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from collections import defaultdict
22
from collections.abc import Mapping, MutableMapping, Sequence
3-
from typing import Any, TypedDict
3+
from typing import Any, NotRequired, TypedDict
44

55
from sentry.api.serializers import Serializer, register, serialize
66
from sentry.grouping.grouptype import ErrorGroupType
@@ -132,15 +132,25 @@ def serialize(
132132
}
133133

134134

135+
class DataConditionHandlerResponse(TypedDict):
136+
type: str
137+
handler_group: str
138+
handler_subgroup: NotRequired[str]
139+
comparison_json_schema: dict
140+
141+
135142
@register(DataConditionHandler)
136143
class DataConditionHandlerSerializer(Serializer):
137-
def serialize(self, obj: DataConditionHandler, *args, **kwargs) -> dict[str, Any]:
144+
def serialize(
145+
self, obj: DataConditionHandler, *args, condition_type: str, **kwargs
146+
) -> DataConditionHandlerResponse:
138147
result = {
139-
"type": obj.type.value,
148+
"type": condition_type,
149+
"handler_group": obj.group.value,
140150
"comparison_json_schema": obj.comparison_json_schema,
141151
}
142-
if hasattr(obj, "filter_group"):
143-
result["filter_group"] = obj.filter_group.value
152+
if hasattr(obj, "subgroup"):
153+
result["handler_subgroup"] = obj.subgroup.value
144154
return result
145155

146156

tests/sentry/workflow_engine/endpoints/test_organization_data_condition_index.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ def setUp(self):
2424
@self.registry.register(Condition.REAPPEARED_EVENT)
2525
@dataclass(frozen=True)
2626
class TestWorkflowTrigger(DataConditionHandler):
27-
type = DataConditionHandler.Type.WORKFLOW_TRIGGER
27+
group = DataConditionHandler.Group.WORKFLOW_TRIGGER
2828
comparison_json_schema = {"type": "boolean"}
2929

3030
@self.registry.register(Condition.AGE_COMPARISON)
3131
@dataclass(frozen=True)
3232
class TestActionFilter(DataConditionHandler):
33-
type = DataConditionHandler.Type.ACTION_FILTER
34-
filter_group = DataConditionHandler.FilterGroup.ISSUE_ATTRIBUTES
33+
group = DataConditionHandler.Group.ACTION_FILTER
34+
subgroup = DataConditionHandler.Subgroup.ISSUE_ATTRIBUTES
3535
comparison_json_schema = {
3636
"type": "object",
3737
"properties": {
@@ -44,14 +44,14 @@ class TestActionFilter(DataConditionHandler):
4444
@self.registry.register(Condition.ANOMALY_DETECTION)
4545
@dataclass(frozen=True)
4646
class TestDetectorTrigger(DataConditionHandler):
47-
type = DataConditionHandler.Type.DETECTOR_TRIGGER
47+
group = DataConditionHandler.Group.DETECTOR_TRIGGER
4848
comparison_json_schema = {"type": "boolean"}
4949

5050
# This condition should not be included in the response
5151
@self.registry.register(Condition.EVERY_EVENT)
5252
@dataclass(frozen=True)
5353
class TestIgnoredCondition(DataConditionHandler):
54-
type = DataConditionHandler.Type.WORKFLOW_TRIGGER
54+
group = DataConditionHandler.Group.WORKFLOW_TRIGGER
5555
comparison_json_schema = {"type": "boolean"}
5656

5757
def tearDown(self) -> None:
@@ -61,25 +61,25 @@ def tearDown(self) -> None:
6161

6262
@region_silo_test
6363
class OrganizationDataCondiitonIndexBaseTest(OrganizationDataConditionAPITestCase):
64-
def test_type_filter(self):
64+
def test_group_filter(self):
6565
response = self.get_success_response(
66-
self.organization.slug, type=DataConditionHandler.Type.WORKFLOW_TRIGGER
66+
self.organization.slug, group=DataConditionHandler.Group.WORKFLOW_TRIGGER
6767
)
6868
assert len(response.data) == 1
6969
assert response.data[0] == {
70-
"condition_id": Condition.REAPPEARED_EVENT.value,
71-
"type": DataConditionHandler.Type.WORKFLOW_TRIGGER.value,
70+
"type": Condition.REAPPEARED_EVENT.value,
71+
"handler_group": DataConditionHandler.Group.WORKFLOW_TRIGGER.value,
7272
"comparison_json_schema": {"type": "boolean"},
7373
}
7474

7575
response = self.get_success_response(
76-
self.organization.slug, type=DataConditionHandler.Type.ACTION_FILTER, status_code=200
76+
self.organization.slug, group=DataConditionHandler.Group.ACTION_FILTER, status_code=200
7777
)
7878
assert len(response.data) == 1
7979
assert response.data[0] == {
80-
"condition_id": Condition.AGE_COMPARISON.value,
81-
"type": DataConditionHandler.Type.ACTION_FILTER.value,
82-
"filter_group": DataConditionHandler.FilterGroup.ISSUE_ATTRIBUTES.value,
80+
"type": Condition.AGE_COMPARISON.value,
81+
"handler_group": DataConditionHandler.Group.ACTION_FILTER.value,
82+
"handler_subgroup": DataConditionHandler.Subgroup.ISSUE_ATTRIBUTES.value,
8383
"comparison_json_schema": {
8484
"type": "object",
8585
"properties": {
@@ -90,8 +90,8 @@ def test_type_filter(self):
9090
},
9191
}
9292

93-
def test_invalid_type(self):
94-
self.get_error_response(self.organization.slug, type="invalid", status_code=400)
93+
def test_invalid_group(self):
94+
self.get_error_response(self.organization.slug, group="invalid", status_code=400)
9595

96-
def test_no_type(self):
96+
def test_no_group(self):
9797
self.get_error_response(self.organization.slug, status_code=400)

0 commit comments

Comments
 (0)