This is an automated email from the ASF dual-hosted git repository. ephraimanierobi pushed a commit to branch v2-4-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 6d0d162fe344e1687e6a28a72cd54feec38f9f8e Author: Jed Cunningham <[email protected]> AuthorDate: Tue Nov 1 16:55:02 2022 -0700 Fix behavior of `_` when searching for DAGs (#27448) On the homepage, when you search for DAGs, `_` wasn't behaving as most people might expect since it is a single character wildcard in SQL. We will automatically escape it now. (cherry picked from commit eda089334864547e18b71cb22fa231872edd4e8b) --- airflow/www/views.py | 5 +++-- tests/www/views/test_views_home.py | 10 +++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/airflow/www/views.py b/airflow/www/views.py index 640adf84df..4b9c7c4bb5 100644 --- a/airflow/www/views.py +++ b/airflow/www/views.py @@ -647,9 +647,10 @@ class Airflow(AirflowBaseView): 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: diff --git a/tests/www/views/test_views_home.py b/tests/www/views/test_views_home.py index 0d1719e89b..369e09ea14 100644 --- a/tests/www/views/test_views_home.py +++ b/tests/www/views/test_views_home.py @@ -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): @@ -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)
