Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix(conditions): treat negative numbers as numbers in ThresholdCondition - #6865

Open
deepanshupal wants to merge 2 commits into
keephq:mainfrom
deepanshupal:fix/threshold-condition-negative-numbers
Open

deepanshupal wants to merge 2 commits into
keephq:mainfrom
deepanshupal:fix/threshold-condition-negative-numbers

Conversation

@deepanshupal

@deepanshupal deepanshupal commented Oct 4, 2026 •

Copy link
Copy Markdown

Closes #6866

Description

ThresholdCondition._validate decides whether compare_to is a number with str(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 for lt, 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. _validate uses it instead of the isdigit() check. The rest of the comparison logic is unchanged.

Tests

test_threshold_condition_negative_numbers in tests/test_conditions.py has 8 cases covering gt and lt with negative thresholds, negative values, and a negative float.

  • With the fix: tests/test_conditions.py 20 passed.
  • With only the source change reverted: 3 of the new cases fail, 17 pass.

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

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation as required
  • All the tests have passed

deepanshupal and others added 2 commits October 4, 2026 08:12
Co-Authored-By: Claude <noreply@anthropic.com>
@CLAassistant

CLAassistant commented Oct 4, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@shahargl shahargl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lgtm

@codecov

codecov Bot commented Oct 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 30.43%. Comparing base (620adaf) to head (d96392c).
⚠️ Report is 7 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛 Bug]: ThresholdCondition compares negative thresholds as text

3 participants