Skip to content

fix(workflows): make pipe-filter split quote/bracket-aware#3261

Closed
Quratulain-bilal wants to merge 1 commit into
github:mainfrom
Quratulain-bilal:fix/expr-pipe-quote-aware
Closed

fix(workflows): make pipe-filter split quote/bracket-aware#3261
Quratulain-bilal wants to merge 1 commit into
github:mainfrom
Quratulain-bilal:fix/expr-pipe-quote-aware

Conversation

@Quratulain-bilal

Copy link
Copy Markdown
Contributor

closes #3260

what

_evaluate_simple_expression split on the first | with a naive if "|" in expr / expr.split("|", 1). unlike the and/or/in/comparison splits (which use _find_top_level to ignore separators inside quoted operands or nested brackets), the pipe split had no such guard. so a | inside a quoted string was treated as a filter pipe:

evaluate_expression("{{ inputs.mode == 'read|write' }}", ctx)
# before: ValueError: unknown filter 'write'
# after:  True

this crashed any workflow gate/when condition or template comparing against a string literal containing |.

fix

use _find_top_level(expr, "|") so only a top-level pipe starts a filter, mirroring the existing operator handling. one-spot change. as a side effect it also fixes join('|') (pipe as the separator argument), which previously mis-split.

tests

added test_pipe_splitting_is_quote_aware in tests/test_workflows.py, mirroring the existing test_operator_splitting_is_quote_aware. verified it fails on the pre-fix code (ValueError: unknown filter 'write') and passes after. full tests/test_workflows.py: 313 passed, 1 skipped.

note: this is separate from #3208/#3228 (which fix the multi-expression fullmatch path in evaluate_expression); this touches the pipe split in _evaluate_simple_expression, a different spot.


note: i used an ai assistant to help investigate and write this up.

_evaluate_simple_expression split on the first '|' with a naive
'if "|" in expr' / expr.split('|', 1), unlike the and/or/comparison
splits which use _find_top_level to ignore separators inside quoted
operands or nested brackets. so a '|' inside a quoted string - e.g. a
gate/when condition like {{ inputs.mode == 'read|write' }} - was treated
as a filter pipe and raised ValueError("unknown filter 'write'"),
crashing the whole expression. use _find_top_level(expr, '|') so only a
top-level pipe starts a filter. also fixes join('|') (pipe as the
separator argument). add a regression test mirroring the existing
quote-aware operator test.
@Quratulain-bilal Quratulain-bilal requested a review from mnriem as a code owner June 30, 2026 15:25
@mnriem mnriem requested a review from Copilot June 30, 2026 15:28
@Quratulain-bilal

Copy link
Copy Markdown
Contributor Author

closing as duplicate — this exact fix already landed in #3232 (same root cause, same _find_top_level approach). sorry for the noise.

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

This PR fixes a parsing bug in the workflow expression evaluator where _evaluate_simple_expression() would incorrectly treat a | that appears inside a quoted string (or nested brackets) as a filter separator, causing spurious “unknown filter …” errors and breaking valid comparisons like inputs.mode == 'read|write'.

Changes:

  • Update pipe-filter splitting in _evaluate_simple_expression() to split only on the first top-level | using _find_top_level(expr, "|").
  • Add a regression test ensuring pipe splitting is quote-aware and that join('|') continues to work correctly.
Show a summary per file
File Description
src/specify_cli/workflows/expressions.py Make pipe-filter splitting quote/bracket-aware by splitting only at top-level `
tests/test_workflows.py Add regression test covering `

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

@Quratulain-bilal Quratulain-bilal deleted the fix/expr-pipe-quote-aware branch June 30, 2026 15:30
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 evaluator mis-parses a pipe inside a quoted string as a filter

3 participants