From c20d31d5d7b405996d8c09102fe3732cb48a28a5 Mon Sep 17 00:00:00 2001 From: pierrejeambrun Date: Thu, 30 Oct 2025 12:26:19 +0100 Subject: [PATCH 1/2] Add number of queries guard in public HITL list endpoints --- .../src/airflow/api_fastapi/core_api/routes/public/hitl.py | 6 ++++-- .../unit/api_fastapi/core_api/routes/public/test_hitl.py | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/hitl.py b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/hitl.py index ecc266c1e5817..58baa5df9aadf 100644 --- a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/hitl.py +++ b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/hitl.py @@ -253,8 +253,10 @@ def get_hitl_details( .join(TI.dag_run) .options( joinedload(HITLDetailModel.task_instance).options( - joinedload(TI.dag_run), - ) + joinedload(TI.dag_run).joinedload(DagRun.dag_model), + joinedload(TI.task_instance_note), + joinedload(TI.dag_version), + ), ) ) if dag_id != "~": diff --git a/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_hitl.py b/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_hitl.py index 4458a2cb80d41..6c55e6eb2ffa8 100644 --- a/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_hitl.py +++ b/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_hitl.py @@ -34,6 +34,7 @@ from airflow.sdk.execution_time.hitl import HITLUser from airflow.utils.state import TaskInstanceState +from tests_common.test_utils.asserts import assert_queries_count from tests_common.test_utils.format_datetime import from_datetime_to_zulu_without_ms if TYPE_CHECKING: @@ -528,7 +529,8 @@ def test_should_respond_200_with_existing_response( test_client: TestClient, expected_sample_hitl_detail_dict: dict[str, Any], ) -> None: - response = test_client.get("/dags/~/dagRuns/~/hitlDetails") + with assert_queries_count(3): + response = test_client.get("/dags/~/dagRuns/~/hitlDetails") assert response.status_code == 200 assert response.json() == { "hitl_details": [expected_sample_hitl_detail_dict], @@ -597,7 +599,8 @@ def test_should_respond_200_with_existing_response_and_query( params: dict[str, Any], expected_ti_count: int, ) -> None: - response = test_client.get("/dags/~/dagRuns/~/hitlDetails", params=params) + with assert_queries_count(3): + response = test_client.get("/dags/~/dagRuns/~/hitlDetails", params=params) assert response.status_code == 200 assert response.json()["total_entries"] == expected_ti_count assert len(response.json()["hitl_details"]) == expected_ti_count From a76a89ffb10654a3800209c0cfa9e1c72fca8bee Mon Sep 17 00:00:00 2001 From: pierrejeambrun Date: Mon, 3 Nov 2025 11:16:10 +0100 Subject: [PATCH 2/2] Fix CI --- .../src/airflow/api_fastapi/core_api/routes/public/hitl.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/hitl.py b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/hitl.py index 58baa5df9aadf..f978a75d4a8f7 100644 --- a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/hitl.py +++ b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/hitl.py @@ -53,6 +53,7 @@ from airflow.api_fastapi.core_api.openapi.exceptions import create_openapi_http_exception_doc from airflow.api_fastapi.core_api.security import GetUserDep, ReadableTIFilterDep, requires_access_dag from airflow.api_fastapi.logging.decorators import action_logging +from airflow.models.dag_version import DagVersion from airflow.models.dagrun import DagRun from airflow.models.hitl import HITLDetail as HITLDetailModel, HITLUser from airflow.models.taskinstance import TaskInstance as TI @@ -255,7 +256,7 @@ def get_hitl_details( joinedload(HITLDetailModel.task_instance).options( joinedload(TI.dag_run).joinedload(DagRun.dag_model), joinedload(TI.task_instance_note), - joinedload(TI.dag_version), + joinedload(TI.dag_version).joinedload(DagVersion.bundle), ), ) )