Skip to content

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

Merged
mnriem merged 1 commit into
github:mainfrom
Quratulain-bilal:fix/safe-compare-string-ordering
Jul 6, 2026
Merged

fix(workflows): compare non-numeric strings lexicographically instead of returning False#3323
mnriem merged 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes workflow expression ordering comparisons so non-numeric strings are compared lexicographically (instead of silently returning False), while preserving numeric-string ordering as numeric comparisons. This improves correctness for common workflow conditions involving dates, tags, and names.

Changes:

  • Add _coerce_number() and update _safe_compare() to only apply numeric coercion when both operands can be treated as numbers; otherwise compare original values (with TypeError yielding False).
  • Add a regression test covering ISO date ordering, plain string ordering, numeric-string ordering, and number-vs-non-numeric-string behavior.
Show a summary per file
File Description
src/specify_cli/workflows/expressions.py Refines _safe_compare to support lexicographic ordering for non-numeric strings while keeping numeric comparisons correct and safe.
tests/test_workflows.py Adds regression coverage to prevent string ordering comparisons from silently returning False.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Low

@mnriem mnriem merged commit 44c112c into github:main Jul 6, 2026
12 checks passed
@mnriem

mnriem commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Thank you!

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

3 participants