-
Notifications
You must be signed in to change notification settings - Fork 18.4k
fix: fix numeric type conversion issue in if-else condition comparison #28155
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
base: main
Are you sure you want to change the base?
Conversation
- Add _normalize_numeric_values function to handle numeric type normalization uniformly - Refactor numeric comparison functions (greater than, less than, greater than or equal, less than or equal) to use unified type conversion logic - Fix comparison issues between integers, floats, and string numeric values - Add unit tests to verify numeric formatting and comparison functionality
Summary of ChangesHello @qiqizjl, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses and resolves a critical bug (issue #28154) in the system's conditional processing logic, specifically concerning numeric type conversion during if-else condition comparisons. Previously, comparing integer values with float strings (e.g., Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request effectively addresses a numeric type conversion issue during condition comparisons by introducing a unified _normalize_numeric_values function. The refactoring of the numeric comparison functions to use this new utility is clean and centralizes the logic, which is a great improvement. The added unit tests correctly verify the fix for comparisons between integers, floats, and numeric strings.
My review includes a suggestion to further improve the consistency of type handling in the new normalization function. I've also added a few comments in the test file to align the code with Python's standard style guidelines (PEP 8), which will enhance readability.
Summary
fix #28154
This PR fixes a numeric type conversion issue in if-else condition comparison functions. When comparing integer values with float strings (e.g.,
0 <= "0.95"), the code was incorrectly converting float strings to integers, causing precision loss and incorrect evaluation results.Changes
_normalize_numeric_valuesfunction to handle numeric type normalization uniformlyRoot Cause
The comparison functions (
_assert_greater_than,_assert_less_than,_assert_greater_than_or_equal,_assert_less_than_or_equal) incore/workflow/utils/condition/processor.pyhad inconsistent type conversion logic. When comparingintvalues with float strings, the code would convert the string toint, losing precision (e.g.,"0.95"becomes0).Solution
Introduced a unified
_normalize_numeric_valuesfunction that:Testing
Added comprehensive unit tests in
tests/unit_tests/core/workflow/utils/test_condition.pycovering:0 <= "0.95",1 >= "0.95")1.1 >= "0.95")1.1 > "0")Screenshots
0 <= "0.95"evaluates toFalse(incorrect)0 <= "0.95"evaluates toTrue(correct)1 >= "0.95"evaluates toFalse(incorrect)1 >= "0.95"evaluates toTrue(correct)Checklist
dev/reformat(backend) andcd web && npx lint-staged(frontend) to appease the lint gods