diff --git a/airflow/api_connexion/endpoints/connection_endpoint.py b/airflow/api_connexion/endpoints/connection_endpoint.py index 9d3224dd8f57c..c17a9280d78f8 100644 --- a/airflow/api_connexion/endpoints/connection_endpoint.py +++ b/airflow/api_connexion/endpoints/connection_endpoint.py @@ -98,11 +98,11 @@ def get_connections( ) -> APIResponse: """Get all connection entries.""" to_replace = {"connection_id": "conn_id"} - allowed_filter_attrs = ["connection_id", "conn_type", "description", "host", "port", "id"] + allowed_sort_attrs = ["connection_id", "conn_type", "description", "host", "port", "id"] total_entries = session.execute(select(func.count(Connection.id))).scalar_one() query = select(Connection) - query = apply_sorting(query, order_by, to_replace, allowed_filter_attrs) + query = apply_sorting(query, order_by, to_replace, allowed_sort_attrs) connections = session.scalars(query.offset(offset).limit(limit)).all() return connection_collection_schema.dump( ConnectionCollection(connections=connections, total_entries=total_entries) diff --git a/airflow/api_connexion/endpoints/dag_run_endpoint.py b/airflow/api_connexion/endpoints/dag_run_endpoint.py index 19373523d845c..99f3ef2893160 100644 --- a/airflow/api_connexion/endpoints/dag_run_endpoint.py +++ b/airflow/api_connexion/endpoints/dag_run_endpoint.py @@ -172,7 +172,7 @@ def _fetch_dag_runs( total_entries = get_query_count(query, session=session) to_replace = {"dag_run_id": "run_id"} - allowed_filter_attrs = [ + allowed_sort_attrs = [ "id", "state", "dag_id", @@ -184,7 +184,7 @@ def _fetch_dag_runs( "external_trigger", "conf", ] - query = apply_sorting(query, order_by, to_replace, allowed_filter_attrs) + query = apply_sorting(query, order_by, to_replace, allowed_sort_attrs) return session.scalars(query.offset(offset).limit(limit)).all(), total_entries diff --git a/airflow/api_connexion/endpoints/dag_warning_endpoint.py b/airflow/api_connexion/endpoints/dag_warning_endpoint.py index 1f480b7111f3d..d59db8c3d3082 100644 --- a/airflow/api_connexion/endpoints/dag_warning_endpoint.py +++ b/airflow/api_connexion/endpoints/dag_warning_endpoint.py @@ -55,7 +55,7 @@ def get_dag_warnings( :param dag_id: the dag_id to optionally filter by :param warning_type: the warning type to optionally filter by """ - allowed_filter_attrs = ["dag_id", "warning_type", "message", "timestamp"] + allowed_sort_attrs = ["dag_id", "warning_type", "message", "timestamp"] query = select(DagWarningModel) if dag_id: query = query.where(DagWarningModel.dag_id == dag_id) @@ -65,7 +65,7 @@ def get_dag_warnings( if warning_type: query = query.where(DagWarningModel.warning_type == warning_type) total_entries = get_query_count(query, session=session) - query = apply_sorting(query=query, order_by=order_by, allowed_attrs=allowed_filter_attrs) + query = apply_sorting(query=query, order_by=order_by, allowed_attrs=allowed_sort_attrs) dag_warnings = session.scalars(query.offset(offset).limit(limit)).all() return dag_warning_collection_schema.dump( DagWarningCollection(dag_warnings=dag_warnings, total_entries=total_entries) diff --git a/airflow/api_connexion/endpoints/import_error_endpoint.py b/airflow/api_connexion/endpoints/import_error_endpoint.py index 59f63c8ffb339..a56cb97c41bfd 100644 --- a/airflow/api_connexion/endpoints/import_error_endpoint.py +++ b/airflow/api_connexion/endpoints/import_error_endpoint.py @@ -84,10 +84,10 @@ def get_import_errors( ) -> APIResponse: """Get all import errors.""" to_replace = {"import_error_id": "id"} - allowed_filter_attrs = ["import_error_id", "timestamp", "filename"] + allowed_sort_attrs = ["import_error_id", "timestamp", "filename"] count_query = select(func.count(ImportErrorModel.id)) query = select(ImportErrorModel) - query = apply_sorting(query, order_by, to_replace, allowed_filter_attrs) + query = apply_sorting(query, order_by, to_replace, allowed_sort_attrs) can_read_all_dags = get_auth_manager().is_authorized_dag(method="GET") diff --git a/airflow/api_connexion/endpoints/pool_endpoint.py b/airflow/api_connexion/endpoints/pool_endpoint.py index e7ce82abbe48a..553d50c7464b7 100644 --- a/airflow/api_connexion/endpoints/pool_endpoint.py +++ b/airflow/api_connexion/endpoints/pool_endpoint.py @@ -75,10 +75,10 @@ def get_pools( ) -> APIResponse: """Get all pools.""" to_replace = {"name": "pool"} - allowed_filter_attrs = ["name", "slots", "id"] + allowed_sort_attrs = ["name", "slots", "id"] total_entries = session.scalars(func.count(Pool.id)).one() query = select(Pool) - query = apply_sorting(query, order_by, to_replace, allowed_filter_attrs) + query = apply_sorting(query, order_by, to_replace, allowed_sort_attrs) pools = session.scalars(query.offset(offset).limit(limit)).all() return pool_collection_schema.dump(PoolCollection(pools=pools, total_entries=total_entries)) diff --git a/airflow/api_connexion/endpoints/variable_endpoint.py b/airflow/api_connexion/endpoints/variable_endpoint.py index a59aa2f4c1b8e..1375484a422fc 100644 --- a/airflow/api_connexion/endpoints/variable_endpoint.py +++ b/airflow/api_connexion/endpoints/variable_endpoint.py @@ -80,9 +80,9 @@ def get_variables( """Get all variable values.""" total_entries = session.execute(select(func.count(Variable.id))).scalar() to_replace = {"value": "val"} - allowed_filter_attrs = ["value", "key", "id"] + allowed_sort_attrs = ["value", "key", "id"] query = select(Variable) - query = apply_sorting(query, order_by, to_replace, allowed_filter_attrs) + query = apply_sorting(query, order_by, to_replace, allowed_sort_attrs) variables = session.scalars(query.offset(offset).limit(limit)).all() return variable_collection_schema.dump( { diff --git a/airflow/providers/fab/auth_manager/api_endpoints/role_and_permission_endpoint.py b/airflow/providers/fab/auth_manager/api_endpoints/role_and_permission_endpoint.py index c291fe69971c0..ed42f91163982 100644 --- a/airflow/providers/fab/auth_manager/api_endpoints/role_and_permission_endpoint.py +++ b/airflow/providers/fab/auth_manager/api_endpoints/role_and_permission_endpoint.py @@ -77,8 +77,8 @@ def get_roles(*, order_by: str = "name", limit: int, offset: int | None = None) to_replace = {"role_id": "id"} order_param = order_by.strip("-") order_param = to_replace.get(order_param, order_param) - allowed_filter_attrs = ["role_id", "name"] - if order_by not in allowed_filter_attrs: + allowed_sort_attrs = ["role_id", "name"] + if order_by not in allowed_sort_attrs: raise BadRequest( detail=f"Ordering with '{order_by}' is disallowed or " f"the attribute does not exist on the model" diff --git a/airflow/providers/fab/auth_manager/api_endpoints/user_endpoint.py b/airflow/providers/fab/auth_manager/api_endpoints/user_endpoint.py index 61bf8e35e60e5..665b7f52d896f 100644 --- a/airflow/providers/fab/auth_manager/api_endpoints/user_endpoint.py +++ b/airflow/providers/fab/auth_manager/api_endpoints/user_endpoint.py @@ -65,7 +65,7 @@ def get_users(*, limit: int, order_by: str = "id", offset: str | None = None) -> to_replace = {"user_id": "id"} order_param = order_by.strip("-") order_param = to_replace.get(order_param, order_param) - allowed_filter_attrs = [ + allowed_sort_attrs = [ "id", "first_name", "last_name", @@ -74,7 +74,7 @@ def get_users(*, limit: int, order_by: str = "id", offset: str | None = None) -> "is_active", "role", ] - if order_by not in allowed_filter_attrs: + if order_by not in allowed_sort_attrs: raise BadRequest( detail=f"Ordering with '{order_by}' is disallowed or " f"the attribute does not exist on the model"