Skip to content

fix(workflows): compare non-numeric strings lexicographically instead of returning False#3323

Open
Quratulain-bilal wants to merge 1 commit into
github:mainfrom
Quratulain-bilal:fix/safe-compare-string-ordering
Open

fix(workflows): compare non-numeric strings lexicographically instead of returning False#3323
Quratulain-bilal wants to merge 1 commit into
github:mainfrom
Quratulain-bilal:fix/safe-compare-string-ordering

Conversation

@Quratulain-bilal

@Quratulain-bilal Quratulain-bilal commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

fixes #3321

what

ordering comparisons (<, >, <=, >=) between non-numeric strings in workflow expressions silently returned False. _safe_compare coerced both operands to int/float unconditionally, so any non-numeric string (iso date, version tag, name) failed coercion and the whole comparison returned False:

ctx = StepContext(inputs={"d": "2026-01-01"})
evaluate_expression("{{ inputs.d < '2026-02-01' }}", ctx)  # was False, want True

how

coerce to a number only when both operands look numeric; otherwise compare the original values. so:

  • two strings order lexicographically like python ("2026-01-01" < "2026-02-01" is True)
  • two numeric strings still compare as numbers ("10" > "9" is True, not lexical False)
  • a number vs a non-numeric string stays incomparable and yields False

==/!= are untouched (they never went through _safe_compare).

tests

added test_ordering_comparison_of_non_numeric_strings (dates, plain strings, numeric strings, number-vs-string). verified it fails on the current code (returns False) and passes with the fix; full TestExpressions passes.

… of returning False

_safe_compare coerced both operands to int/float unconditionally for <, >, <=,
>=. any non-numeric string (an iso date, a version tag, a name) failed that
coercion and the whole comparison silently returned False -- so
`{{ inputs.d < '2026-02-01' }}` was False even when the date was earlier.

only coerce when both operands look numeric; otherwise compare the original
values, so two strings order lexicographically the way python does and two
numeric strings still compare as numbers ("10" > "9"). a number vs a
non-numeric string stays incomparable and yields False.

add a regression test covering dates, plain strings, numeric strings, and the
number-vs-string case.
@Quratulain-bilal Quratulain-bilal requested a review from mnriem as a code owner July 3, 2026 15:45
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: workflow expression ordering comparisons return False for non-numeric strings

1 participant