Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def to_orm(self, select: Select) -> Select:
val_str = str(self.value)
if "|" in val_str:
search_terms = [term.strip() for term in val_str.split("|") if term.strip()]
if len(search_terms) > 1:
if search_terms:
return select.where(or_(*(self.attribute.ilike(f"%{term}%") for term in search_terms)))

return select.where(self.attribute.ilike(f"%{self.value}%"))
Expand Down
20 changes: 20 additions & 0 deletions airflow-core/tests/unit/api_fastapi/common/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,23 @@ def test_to_orm_multiple_values_or(self):
assert "OR" in sql
assert "example_bash" in sql
assert "example_python" in sql

def test_to_orm_pipe_with_trailing_pipe(self):
"""Test that a trailing pipe is ignored and only the valid term is searched."""
param = _SearchParam(DagModel.dag_id).set_value("example_bash|")
statement = select(DagModel)
statement = param.to_orm(statement)

sql = str(statement.compile(compile_kwargs={"literal_binds": True}))
assert "example_bash" in sql
assert "|" not in sql

def test_to_orm_pipe_with_leading_pipe(self):
"""Test that a leading pipe is ignored and only the valid term is searched."""
param = _SearchParam(DagModel.dag_id).set_value("|example_bash")
statement = select(DagModel)
statement = param.to_orm(statement)

sql = str(statement.compile(compile_kwargs={"literal_binds": True}))
assert "example_bash" in sql
assert "|" not in sql
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,11 @@ def test_bad_limit_and_offset(self, test_client, query_params, expected_detail):
(DAG1_ID, {"run_id_pattern": "run_1"}, [DAG1_RUN1_ID]),
(DAG1_ID, {"run_id_pattern": "dag_%_1"}, [DAG1_RUN1_ID]),
("~", {"run_id_pattern": "dag_run_"}, [DAG1_RUN1_ID, DAG1_RUN2_ID, DAG2_RUN1_ID, DAG2_RUN2_ID]),
# Pipe (OR) operator returns results matching either term
("~", {"run_id_pattern": f"{DAG1_RUN1_ID}|{DAG1_RUN2_ID}"}, [DAG1_RUN1_ID, DAG1_RUN2_ID]),
# Trailing/leading pipe should not leak into the LIKE pattern
("~", {"run_id_pattern": f"{DAG1_RUN1_ID}|"}, [DAG1_RUN1_ID]),
("~", {"run_id_pattern": f"|{DAG1_RUN1_ID}"}, [DAG1_RUN1_ID]),
(
DAG1_ID,
{
Expand Down
Loading