Repository navigation
fix(conditions): treat negative numbers as numbers in ThresholdCondition - #6865
Open
deepanshupal wants to merge 2 commits into
Open
deepanshupal wants to merge 2 commits into
deepanshupal wants to merge 2 commits into
Conversation
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6865 +/- ##
==========================================
- Coverage 30.45% 30.43% -0.02%
==========================================
Files 101 101
Lines 11785 11791 +6
==========================================
Hits 3589 3589
- Misses 8196 8202 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Closes #6866
Description
ThresholdCondition._validatedecides whethercompare_tois a number withstr(compare_to).replace(".", "", 1).isdigit(). That is False for any negative number, because of the leading "-". A negative threshold is then compared to the value as text instead of as a number.Example with
compare_type: gt, threshold"-5"and value"-3": the strings compare as"-3" > "-5", which is False. Numerically -3 is greater than -5, so the condition should fire and it does not. The same text comparison gives wrong results forlt, for-5.5, and for a negative threshold against a positive value.Fix
Add
ThresholdCondition._is_number(), which accepts an optional sign, decimals and exponents, and rejects bools._validateuses it instead of theisdigit()check. The rest of the comparison logic is unchanged.Tests
test_threshold_condition_negative_numbersintests/test_conditions.pyhas 8 cases coveringgtandltwith negative thresholds, negative values, and a negative float.tests/test_conditions.py20 passed.I searched open and closed issues and PRs for this and found no duplicate. #6603 (percentage thresholds) touched the same method but not negative numbers.
AI disclosure
This change was prepared with AI assistance (Claude). I reviewed the diff and ran the tests locally.
Checks