coleheflin opened a new pull request, #65190:
URL: https://github.com/apache/airflow/pull/65190

   When `run_id_pattern` (and other `_SearchParam`-based filters) contained a 
trailing or leading pipe character — e.g. `term|` or `|term` — the existing 
guard `if len(search_terms) > 1` evaluated to `False` for the single remaining 
term and fell through to the raw fallback:
   
   ```python
   select.where(self.attribute.ilike(f"%{self.value}%"))
   # → LIKE '%term|%'  or  LIKE '%|term%'
   ```
   
   Neither pattern matches any realistic run ID, so the endpoint silently 
returned an empty list instead of the expected results.
   
   ## 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 cleanly to just that 
condition (no spurious `OR` keyword), so no SQL correctness risk. The fix 
applies to every endpoint that uses `_SearchParam` via `search_param_factory` 
(`run_id_pattern`, `dag_id_pattern`, `task_id_pattern`, etc.).
   
   **`airflow-core/tests/unit/api_fastapi/common/test_parameters.py`**
   
   Three new unit tests on `_SearchParam.to_orm`:
   - `test_to_orm_multiple_values_or_no_spaces` — pipe without surrounding 
spaces (`"a|b"`)
   - `test_to_orm_pipe_with_trailing_pipe` — single term with trailing pipe 
(`"term|"`) — **regression test**, fails without the fix
   - `test_to_orm_pipe_with_leading_pipe` — single term with leading pipe 
(`"|term"`) — **regression test**, fails without the fix
   
   
**`airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dag_run.py`**
   
   Six new parametrize cases on `TestGetDagRuns::test_filters`:
   - OR without spaces: `dag_run_1|dag_run_2` → returns both runs
   - OR with spaces: `dag_run_1 | dag_run_2` → returns both runs
   - OR scoped to a specific DAG
   - OR with one valid + one non-existent term → returns only the matching run
   - Trailing pipe `dag_run_1|` → returns `dag_run_1` — **regression test**, 
fails without the fix
   - Leading pipe `|dag_run_1` → returns `dag_run_1` — **regression test**, 
fails without the fix
   
   ## Test results
   
   ```
   # With fix applied
   73 passed (5 unit + 68 integration)
   
   # With fix reverted — regression tests correctly fail
   FAILED test_filters[~-query_params32-...] - AssertionError: [] != 
['dag_run_1']
   FAILED test_filters[~-query_params33-...] - AssertionError: [] != 
['dag_run_1']
   2 failed, 71 passed
   ```
   
   closes: #65129
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — Claude Sonnet 4.6 (claude-sonnet-4-6)
   
   Generated-by: Claude Sonnet 4.6 following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to