Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix behavior of _ when searching for DAGs #27448

Merged
merged 3 commits into from
Nov 1, 2022
Merged
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
5 changes: 3 additions & 2 deletions airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,10 @@ def index(self):
dags_query = session.query(DagModel).filter(~DagModel.is_subdag, DagModel.is_active)

if arg_search_query:
escaped_arg_search_query = arg_search_query.replace("_", r"\_")
dags_query = dags_query.filter(
DagModel.dag_id.ilike('%' + arg_search_query + '%')
| DagModel.owners.ilike('%' + arg_search_query + '%')
DagModel.dag_id.ilike("%" + escaped_arg_search_query + "%", escape="\\")
| DagModel.owners.ilike("%" + escaped_arg_search_query + "%", escape="\\")
)

if arg_tags_filter:
Expand Down
10 changes: 9 additions & 1 deletion tests/www/views/test_views_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def client_single_dag(app, user_single_dag):
)


TEST_FILTER_DAG_IDS = ["filter_test_1", "filter_test_2", "a_first_dag_id_asc"]
TEST_FILTER_DAG_IDS = ["filter_test_1", "filter_test_2", "a_first_dag_id_asc", "filter.test"]


def _process_file(file_path, session):
Expand Down Expand Up @@ -185,6 +185,14 @@ def test_home_dag_list_filtered_singledag_user(working_dags, client_single_dag):
check_content_not_in_response(f"dag_id={dag_id}", resp)


def test_home_dag_list_search(working_dags, user_client):
resp = user_client.get("home?search=filter_test", follow_redirects=True)
check_content_in_response("dag_id=filter_test_1", resp)
check_content_in_response("dag_id=filter_test_2", resp)
check_content_not_in_response("dag_id=filter.test", resp)
check_content_not_in_response("dag_id=a_first_dag_id_asc", resp)


def test_home_robots_header_in_response(user_client):
# Responses should include X-Robots-Tag header
resp = user_client.get("home", follow_redirects=True)
Expand Down