-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
nit(aci): handle NaN aggregation value in subscription processor #105704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
||
| @patch("sentry.incidents.subscription_processor.metrics") | ||
| def test_invalid_aggregation_value(self, mock_metrics: MagicMock) -> None: | ||
| self.send_update("nan") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you might want the value to be float("nan") to actually make it a nan rather than a string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strings are by default not numbers so I think any string is okay (if we do the math.isnan check)
| aggregation_value = self.get_aggregation_value(subscription_update, comparison_delta) | ||
|
|
||
| if aggregation_value is None: | ||
| if aggregation_value is None or math.isnan(aggregation_value): |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
| aggregation_value = self.get_aggregation_value(subscription_update, comparison_delta) | ||
|
|
||
| if aggregation_value is None: | ||
| if aggregation_value is None or math.isnan(aggregation_value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
math.isnan() crashes on non-numeric aggregation values
High Severity
The math.isnan() function requires a numeric argument and raises TypeError for non-numeric types. When aggregation_value is a non-numeric, non-None value (like a string), the condition aggregation_value is None is False, causing math.isnan(aggregation_value) to be evaluated and crash. The test sends "not a number" string which would trigger this TypeError. A type check is needed before calling math.isnan(), or use a pattern like isinstance(aggregation_value, (int, float)) and math.isnan(aggregation_value).
Additional Locations (1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's ever possible to not send a numeric value; fixed the test
Since we know before data condition evaluation that this is the case, skip processing and return early.