Skip to content

Fix run_id_pattern pipe OR operator dropping single-term edge cases#65190

Draft
coleheflin wants to merge 1 commit intoapache:mainfrom
coleheflin:fix/run-id-pattern-pipe-edge-cases
Draft

Fix run_id_pattern pipe OR operator dropping single-term edge cases#65190
coleheflin wants to merge 1 commit intoapache:mainfrom
coleheflin:fix/run-id-pattern-pipe-edge-cases

Conversation

@coleheflin
Copy link
Copy Markdown
Contributor

@coleheflin coleheflin commented Apr 14, 2026

When run_id_pattern (or any other _SearchParam-based filter) received a trailing or leading pipe — e.g. term| or |term — the guard if len(search_terms) > 1 evaluated False for the single remaining term and fell through to the raw fallback:

select.where(self.attribute.ilike(f"%{self.value}%"))
# → LIKE '%term|%'  or  LIKE '%|term%'

Neither pattern matches any realistic value, so the endpoint silently returned an empty list.

Changes

airflow-core/src/airflow/api_fastapi/common/parameters.py — one-character fix: if len(search_terms) > 1:if search_terms:. SQLAlchemy's or_() with a single argument compiles to just that condition, so no SQL correctness risk. Applies to every endpoint using search_param_factory.

airflow-core/tests/unit/api_fastapi/common/test_parameters.py — two unit regression tests for trailing/leading pipe edge cases.

airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dag_run.py — three integration tests: one proving the basic OR case (a|b returns both runs, directly demonstrating the reported behaviour works), and two regression tests for the trailing/leading pipe edge cases.

Test results

# Fix applied — all pass
65 passed

# Fix reverted — regression tests correctly fail
FAILED test_to_orm_pipe_with_trailing_pipe  →  LIKE '%example_bash|%' contains '|'
FAILED test_to_orm_pipe_with_leading_pipe   →  LIKE '%|example_bash%' contains '|'
FAILED test_filters[trailing pipe]          →  [] != ['dag_run_1']
FAILED test_filters[leading pipe]           →  [] != ['dag_run_1']
4 failed, 61 passed

closes: #65129


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Sonnet 4.6 (claude-sonnet-4-6)

Generated-by: Claude Sonnet 4.6 following the guidelines

@boring-cyborg boring-cyborg bot added the area:API Airflow's REST/HTTP API label Apr 14, 2026
@coleheflin coleheflin force-pushed the fix/run-id-pattern-pipe-edge-cases branch from 29e8fdf to a134e7e Compare April 14, 2026 04:03
When a pattern like "term|" or "|term" was passed, the OR-split guard
`if len(search_terms) > 1` evaluated False for the single remaining
term, falling through to `ilike("%term|%")` / `ilike("%|term%")` which
matched nothing. Changing the guard to `if search_terms:` ensures a
single valid term is used correctly.

closes: apache#65129
@coleheflin coleheflin force-pushed the fix/run-id-pattern-pipe-edge-cases branch from a134e7e to a9e0f92 Compare April 14, 2026 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rest api: run_id_pattern does not handle pipe(OR) operator

1 participant