Skip to content

Commit c4fdd12

Browse files
committed
typing
1 parent 1be2032 commit c4fdd12

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/sentry/incidents/metric_issue_detector.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from datetime import timedelta
2-
from typing import Any
2+
from typing import Any, cast
33

44
from rest_framework import serializers
55

@@ -233,7 +233,8 @@ def update_data_source(self, instance: Detector, data_source: SnubaQueryDataSour
233233
"query"
234234
) or snuba_query.aggregate != data_source.get("aggregate"):
235235
try:
236-
update_detector_data(instance, data_source)
236+
validated_data_source = cast(dict[str, Any], data_source)
237+
update_detector_data(instance, validated_data_source)
237238
except Exception:
238239
# don't update the snuba query if we failed to send data to Seer
239240
raise serializers.ValidationError(

src/sentry/seer/anomaly_detection/store_data_workflow_engine.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
def _fetch_related_models(
4545
detector: Detector, method: str
46-
) -> tuple[DataSource, DataCondition, SnubaQuery] | None:
46+
) -> tuple[DataSource, DataCondition, SnubaQuery]:
4747
# XXX: it is technically possible (though not used today) that a detector could have multiple data sources
4848
data_source_detector = DataSourceDetector.objects.filter(detector_id=detector.id).first()
4949
if not data_source_detector:
@@ -84,6 +84,7 @@ def update_detector_data(
8484
updated_fields: dict[str, Any],
8585
) -> None:
8686
data_source, data_condition, snuba_query = _fetch_related_models(detector, "update")
87+
8788
# use setattr to avoid saving the models until the Seer call has successfully finished,
8889
# otherwise they would be in a bad state
8990
updated_data_condition_data = updated_fields.get("condition_group", {}).get("conditions")
@@ -127,6 +128,7 @@ def send_new_detector_data(detector: Detector) -> None:
127128
Send historical data for a new Detector to Seer.
128129
"""
129130
data_source, data_condition, snuba_query = _fetch_related_models(detector, "create")
131+
130132
try:
131133
handle_send_historical_data_to_seer(
132134
detector, data_source, data_condition, snuba_query, detector.project, SeerMethod.CREATE

tests/sentry/incidents/endpoints/validators/test_validators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def setUp(self) -> None:
188188
},
189189
}
190190

191-
def create_static_detector(self) -> None:
191+
def create_static_detector(self) -> Detector:
192192
validator = MetricIssueDetectorValidator(
193193
data=self.valid_data,
194194
context=self.context,
@@ -218,7 +218,7 @@ def create_static_detector(self) -> None:
218218

219219
return static_detector
220220

221-
def create_dynamic_detector(self) -> None:
221+
def create_dynamic_detector(self) -> Detector:
222222
validator = MetricIssueDetectorValidator(
223223
data=self.valid_anomaly_detection_data,
224224
context=self.context,

0 commit comments

Comments
 (0)