feat(tracemetrics): Bypass metric field validation for equations#112479
Open
narsaynorath wants to merge 5 commits intomasterfrom
Open
feat(tracemetrics): Bypass metric field validation for equations#112479narsaynorath wants to merge 5 commits intomasterfrom
narsaynorath wants to merge 5 commits intomasterfrom
Conversation
Member
Author
|
There's a chance that, since we encode the metric name in the aggregate function now, this validation can go away, but for now I do not want to make that change because frontend code may be reliant on this field being filled out. Post-GA we can circle back and see if this field is still necessary, but for now we do not need to do large changes to account for this. |
This comment was marked as outdated.
This comment was marked as outdated.
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed:
all()on empty iterable bypasses metric validation- Fixed by collecting y_axes into a list and checking both that the list is non-empty AND that all items are equations, ensuring has_equations is only True when actual equation y-axes are present.
Or push these changes by commenting:
@cursor push 1300763d88
Preview (1300763d88)
diff --git a/src/sentry/explore/endpoints/serializers.py b/src/sentry/explore/endpoints/serializers.py
--- a/src/sentry/explore/endpoints/serializers.py
+++ b/src/sentry/explore/endpoints/serializers.py
@@ -225,11 +225,12 @@
)
# the metrics field is only required for non-equation queries
- has_equations = all(
- is_equation(y_axis)
+ y_axes = [
+ y_axis
for aggregate_field in q.get("aggregateField") or []
for y_axis in aggregate_field.get("yAxes") or []
- )
+ ]
+ has_equations = len(y_axes) > 0 and all(is_equation(y_axis) for y_axis in y_axes)
if data["dataset"] == "metrics" and not has_equations and "metric" not in q:
raise serializers.ValidationError(
"Metric field is required for non-equation queries on the metrics dataset"This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 2156b77. Configure here.
This comment was marked as outdated.
This comment was marked as outdated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


We enforce that there's a
metricpayload for saved queries, but when a user is plotting an equation, there can be multiplemetrics involved, so this field no longer makes sense.This PR relaxes the constraint so
metriccan be skipped if the user is querying an equation (i.e. we check if there's theequation|prefix)