Skip to content

Conversation

@mifu67
Copy link
Contributor

@mifu67 mifu67 commented Nov 6, 2025

Verify on the backend that metric detectors have a resolution condition.

@mifu67 mifu67 requested a review from a team as a code owner November 6, 2025 21:52
@mifu67 mifu67 requested review from a team and ceorourke November 6, 2025 21:52
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 6, 2025
(
Condition.GREATER,
Condition.LESS,
Condition.GREATER_OR_EQUAL,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this and the condition below it are used for resolution

@codecov
Copy link

codecov bot commented Nov 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #102922      +/-   ##
===========================================
+ Coverage   79.61%    80.65%   +1.03%     
===========================================
  Files        9015      9015              
  Lines      392406    392455      +49     
  Branches    24968     24968              
===========================================
+ Hits       312425    316516    +4091     
+ Misses      79584     75542    -4042     
  Partials      397       397              

if "condition_group" in attrs:
conditions = attrs.get("condition_group", {}).get("conditions")
if len(conditions) > 2:
if len(conditions) > 3:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high, medium, ok

) and not any(condition["type"] == Condition.ANOMALY_DETECTION for condition in value):
raise serializers.ValidationError(
"Resolution condition required for metric issue detector."
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Validation bypass: raw input used after validation

The validate_conditions method validates the condition data with MetricIssueComparisonConditionValidator but discards the validated data. The resolution check then uses the raw input value instead of the validated data where condition_result has been properly converted to DetectorPriorityLevel enum. This causes the validation to incorrectly fail when condition_result is passed as a string (e.g., "0") rather than an integer, since string-to-enum comparison returns false.

Fix in Cursor Fix in Web

class MetricIssueConditionGroupValidator(BaseDataConditionGroupValidator):
conditions = serializers.ListField(required=True)

def validate_conditions(self, value):
Copy link
Member

@malwilley malwilley Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wondering out loud (not feedback on this specific PR): do we have any validation on the backend that the condition values are valid against each other? There's a lot of logic on the frontend to prevent it, but it could be an issue for API users or if we have a bug on the frontend

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I'm not sure we do 🤔 I'll add some more validation in a follow up PR.

@mifu67 mifu67 merged commit bfdee7b into master Nov 7, 2025
66 checks passed
@mifu67 mifu67 deleted the mifu67/aci/validate-resolution branch November 7, 2025 18:36
Jesse-Box pushed a commit that referenced this pull request Nov 12, 2025
…or validator (#102922)

Verify on the backend that metric detectors have a resolution condition.
andrewshie-sentry pushed a commit that referenced this pull request Nov 13, 2025
…or validator (#102922)

Verify on the backend that metric detectors have a resolution condition.
@github-actions github-actions bot locked and limited conversation to collaborators Nov 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants