This is an automated email from the ASF dual-hosted git repository.

pierrejeambrun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 5af0ec9ed16 AIP-84: alias `dag_display_name` for `DagRun` (#49933)
5af0ec9ed16 is described below

commit 5af0ec9ed16788f84783c5fa52504976f0cddfb8
Author: Guan Ming(Wesley) Chiu <[email protected]>
AuthorDate: Tue Apr 29 20:45:12 2025 +0800

    AIP-84: alias `dag_display_name` for `DagRun` (#49933)
    
    * AIP-84: alias dag_display_name for `DagRun`
    
    * test: update unit test
---
 .../airflow/api_fastapi/core_api/datamodels/dag_run.py  |  3 ++-
 .../api_fastapi/core_api/openapi/_private_ui.yaml       |  4 ++++
 .../core_api/openapi/v1-rest-api-generated.yaml         |  4 ++++
 .../api_fastapi/core_api/routes/public/dag_run.py       | 17 ++++++++++++-----
 .../src/airflow/ui/openapi-gen/requests/schemas.gen.ts  |  5 +++++
 .../src/airflow/ui/openapi-gen/requests/types.gen.ts    |  1 +
 .../api_fastapi/core_api/routes/public/test_assets.py   |  1 +
 .../api_fastapi/core_api/routes/public/test_dag_run.py  |  5 +++++
 .../tests/unit/cli/commands/test_asset_command.py       |  1 +
 airflow-ctl/src/airflowctl/api/datamodels/generated.py  |  1 +
 airflow-ctl/tests/airflow_ctl/api/test_operations.py    |  1 +
 11 files changed, 37 insertions(+), 6 deletions(-)

diff --git 
a/airflow-core/src/airflow/api_fastapi/core_api/datamodels/dag_run.py 
b/airflow-core/src/airflow/api_fastapi/core_api/datamodels/dag_run.py
index 49661dfd5db..966de7e78f7 100644
--- a/airflow-core/src/airflow/api_fastapi/core_api/datamodels/dag_run.py
+++ b/airflow-core/src/airflow/api_fastapi/core_api/datamodels/dag_run.py
@@ -21,7 +21,7 @@ from datetime import datetime
 from enum import Enum
 from typing import TYPE_CHECKING
 
-from pydantic import AwareDatetime, Field, NonNegativeInt, model_validator
+from pydantic import AliasPath, AwareDatetime, Field, NonNegativeInt, 
model_validator
 
 from airflow.api_fastapi.core_api.base import BaseModel, StrictBaseModel
 from airflow.api_fastapi.core_api.datamodels.dag_versions import 
DagVersionResponse
@@ -77,6 +77,7 @@ class DAGRunResponse(BaseModel):
     note: str | None
     dag_versions: list[DagVersionResponse]
     bundle_version: str | None
+    dag_display_name: str = Field(validation_alias=AliasPath("dag_model", 
"dag_display_name"))
 
 
 class DAGRunCollectionResponse(BaseModel):
diff --git 
a/airflow-core/src/airflow/api_fastapi/core_api/openapi/_private_ui.yaml 
b/airflow-core/src/airflow/api_fastapi/core_api/openapi/_private_ui.yaml
index 62b743e0eda..d07fef629e2 100644
--- a/airflow-core/src/airflow/api_fastapi/core_api/openapi/_private_ui.yaml
+++ b/airflow-core/src/airflow/api_fastapi/core_api/openapi/_private_ui.yaml
@@ -945,6 +945,9 @@ components:
           - type: string
           - type: 'null'
           title: Bundle Version
+        dag_display_name:
+          type: string
+          title: Dag Display Name
       type: object
       required:
       - dag_run_id
@@ -964,6 +967,7 @@ components:
       - note
       - dag_versions
       - bundle_version
+      - dag_display_name
       title: DAGRunResponse
       description: DAG Run serializer for responses.
     DAGRunStates:
diff --git 
a/airflow-core/src/airflow/api_fastapi/core_api/openapi/v1-rest-api-generated.yaml
 
b/airflow-core/src/airflow/api_fastapi/core_api/openapi/v1-rest-api-generated.yaml
index c705137d0a6..0cf4c38f93a 100644
--- 
a/airflow-core/src/airflow/api_fastapi/core_api/openapi/v1-rest-api-generated.yaml
+++ 
b/airflow-core/src/airflow/api_fastapi/core_api/openapi/v1-rest-api-generated.yaml
@@ -8342,6 +8342,9 @@ components:
           - type: string
           - type: 'null'
           title: Bundle Version
+        dag_display_name:
+          type: string
+          title: Dag Display Name
       type: object
       required:
       - dag_run_id
@@ -8361,6 +8364,7 @@ components:
       - note
       - dag_versions
       - bundle_version
+      - dag_display_name
       title: DAGRunResponse
       description: DAG Run serializer for responses.
     DAGRunsBatchBody:
diff --git 
a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dag_run.py 
b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dag_run.py
index 7b12593994f..a3a70009360 100644
--- a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dag_run.py
+++ b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dag_run.py
@@ -24,6 +24,7 @@ from fastapi import Depends, HTTPException, Query, Request, 
status
 from fastapi.exceptions import RequestValidationError
 from pydantic import ValidationError
 from sqlalchemy import select
+from sqlalchemy.orm import joinedload
 
 from airflow.api.common.mark_tasks import (
     set_dag_run_state_to_failed,
@@ -90,7 +91,9 @@ dag_run_router = AirflowRouter(tags=["DagRun"], 
prefix="/dags/{dag_id}/dagRuns")
     dependencies=[Depends(requires_access_dag(method="GET", 
access_entity=DagAccessEntity.RUN))],
 )
 def get_dag_run(dag_id: str, dag_run_id: str, session: SessionDep) -> 
DAGRunResponse:
-    dag_run = session.scalar(select(DagRun).filter_by(dag_id=dag_id, 
run_id=dag_run_id))
+    dag_run = session.scalar(
+        select(DagRun).filter_by(dag_id=dag_id, 
run_id=dag_run_id).options(joinedload(DagRun.dag_model))
+    )
     if dag_run is None:
         raise HTTPException(
             status.HTTP_404_NOT_FOUND,
@@ -149,7 +152,9 @@ def patch_dag_run(
     update_mask: list[str] | None = Query(None),
 ) -> DAGRunResponse:
     """Modify a DAG Run."""
-    dag_run = session.scalar(select(DagRun).filter_by(dag_id=dag_id, 
run_id=dag_run_id))
+    dag_run = session.scalar(
+        select(DagRun).filter_by(dag_id=dag_id, 
run_id=dag_run_id).options(joinedload(DagRun.dag_model))
+    )
     if dag_run is None:
         raise HTTPException(
             status.HTTP_404_NOT_FOUND,
@@ -253,7 +258,9 @@ def clear_dag_run(
     request: Request,
     session: SessionDep,
 ) -> TaskInstanceCollectionResponse | DAGRunResponse:
-    dag_run = session.scalar(select(DagRun).filter_by(dag_id=dag_id, 
run_id=dag_run_id))
+    dag_run = session.scalar(
+        select(DagRun).filter_by(dag_id=dag_id, 
run_id=dag_run_id).options(joinedload(DagRun.dag_model))
+    )
     if dag_run is None:
         raise HTTPException(
             status.HTTP_404_NOT_FOUND,
@@ -338,7 +345,7 @@ def get_dag_runs(
         if not dag:
             raise HTTPException(status.HTTP_404_NOT_FOUND, f"The DAG with 
dag_id: `{dag_id}` was not found")
 
-        query = query.filter(DagRun.dag_id == dag_id)
+        query = query.filter(DagRun.dag_id == 
dag_id).options(joinedload(DagRun.dag_model))
 
     dag_run_select, total_entries = paginated_select(
         statement=query,
@@ -474,7 +481,7 @@ def get_list_dag_runs_batch(
         {"dag_run_id": "run_id"},
     ).set_value(body.order_by)
 
-    base_query = select(DagRun)
+    base_query = select(DagRun).options(joinedload(DagRun.dag_model))
     dag_runs_select, total_entries = paginated_select(
         statement=base_query,
         filters=[dag_ids, logical_date, run_after, start_date, end_date, 
state, readable_dag_runs_filter],
diff --git a/airflow-core/src/airflow/ui/openapi-gen/requests/schemas.gen.ts 
b/airflow-core/src/airflow/ui/openapi-gen/requests/schemas.gen.ts
index 1f8120ec863..68f9e8afa0f 100644
--- a/airflow-core/src/airflow/ui/openapi-gen/requests/schemas.gen.ts
+++ b/airflow-core/src/airflow/ui/openapi-gen/requests/schemas.gen.ts
@@ -2266,6 +2266,10 @@ export const $DAGRunResponse = {
       ],
       title: "Bundle Version",
     },
+    dag_display_name: {
+      type: "string",
+      title: "Dag Display Name",
+    },
   },
   type: "object",
   required: [
@@ -2286,6 +2290,7 @@ export const $DAGRunResponse = {
     "note",
     "dag_versions",
     "bundle_version",
+    "dag_display_name",
   ],
   title: "DAGRunResponse",
   description: "DAG Run serializer for responses.",
diff --git a/airflow-core/src/airflow/ui/openapi-gen/requests/types.gen.ts 
b/airflow-core/src/airflow/ui/openapi-gen/requests/types.gen.ts
index 591f22b2e6f..84555019afd 100644
--- a/airflow-core/src/airflow/ui/openapi-gen/requests/types.gen.ts
+++ b/airflow-core/src/airflow/ui/openapi-gen/requests/types.gen.ts
@@ -578,6 +578,7 @@ export type DAGRunResponse = {
   note: string | null;
   dag_versions: Array<DagVersionResponse>;
   bundle_version: string | null;
+  dag_display_name: string;
 };
 
 /**
diff --git 
a/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_assets.py 
b/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_assets.py
index 6a3f889cfe2..be1784a17ac 100644
--- a/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_assets.py
+++ b/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_assets.py
@@ -1145,6 +1145,7 @@ class TestPostAssetMaterialize(TestAssets):
         assert response.status_code == 200
         assert response.json() == {
             "bundle_version": None,
+            "dag_display_name": self.DAG_ASSET1_ID,
             "dag_run_id": mock.ANY,
             "dag_id": self.DAG_ASSET1_ID,
             "dag_versions": mock.ANY,
diff --git 
a/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dag_run.py 
b/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dag_run.py
index 2d60fedbd19..3c4d16072bc 100644
--- a/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dag_run.py
+++ b/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dag_run.py
@@ -52,6 +52,7 @@ if TYPE_CHECKING:
 pytestmark = pytest.mark.db_test
 
 DAG1_ID = "test_dag1"
+DAG1_DISPLAY_NAME = "test_dag1"
 DAG2_ID = "test_dag2"
 DAG1_RUN1_ID = "dag_run_1"
 DAG1_RUN2_ID = "dag_run_2"
@@ -168,6 +169,7 @@ def get_dag_versions_dict(dag_versions: list[DagVersion]) 
-> list[dict]:
 def get_dag_run_dict(run: DagRun):
     return {
         "bundle_version": None,
+        "dag_display_name": run.dag_model.dag_display_name,
         "dag_run_id": run.run_id,
         "dag_id": run.dag_id,
         "logical_date": from_datetime_to_zulu_without_ms(run.logical_date),
@@ -1306,6 +1308,7 @@ class TestTriggerDagRun:
         expected_response_json = {
             "bundle_version": None,
             "conf": {},
+            "dag_display_name": DAG1_DISPLAY_NAME,
             "dag_id": DAG1_ID,
             "dag_run_id": expected_dag_run_id,
             "dag_versions": get_dag_versions_dict(run.dag_versions),
@@ -1495,6 +1498,7 @@ class TestTriggerDagRun:
         assert response_1.status_code == 200
         assert response_1.json() == {
             "bundle_version": None,
+            "dag_display_name": DAG1_DISPLAY_NAME,
             "dag_run_id": RUN_ID_1,
             "dag_id": DAG1_ID,
             "dag_versions": mock.ANY,
@@ -1580,6 +1584,7 @@ class TestTriggerDagRun:
         assert response.status_code == 200
         assert response.json() == {
             "bundle_version": None,
+            "dag_display_name": DAG1_DISPLAY_NAME,
             "dag_run_id": mock.ANY,
             "dag_id": DAG1_ID,
             "dag_versions": mock.ANY,
diff --git a/airflow-core/tests/unit/cli/commands/test_asset_command.py 
b/airflow-core/tests/unit/cli/commands/test_asset_command.py
index 738dceadbf6..ea68786eaa0 100644
--- a/airflow-core/tests/unit/cli/commands/test_asset_command.py
+++ b/airflow-core/tests/unit/cli/commands/test_asset_command.py
@@ -142,6 +142,7 @@ def test_cli_assets_materialize(parser: ArgumentParser) -> 
None:
     assert run_list[0] | undeterministic == undeterministic | {
         "conf": {},
         "bundle_version": None,
+        "dag_display_name": "asset1_producer",
         "dag_id": "asset1_producer",
         "end_date": None,
         "last_scheduling_decision": None,
diff --git a/airflow-ctl/src/airflowctl/api/datamodels/generated.py 
b/airflow-ctl/src/airflowctl/api/datamodels/generated.py
index f55e46016a9..9eb789e1151 100644
--- a/airflow-ctl/src/airflowctl/api/datamodels/generated.py
+++ b/airflow-ctl/src/airflowctl/api/datamodels/generated.py
@@ -1220,6 +1220,7 @@ class DAGRunResponse(BaseModel):
     note: Annotated[str | None, Field(title="Note")] = None
     dag_versions: Annotated[list[DagVersionResponse], Field(title="Dag 
Versions")]
     bundle_version: Annotated[str | None, Field(title="Bundle Version")] = None
+    dag_display_name: Annotated[str, Field(title="Dag Display Name")]
 
 
 class DAGRunsBatchBody(BaseModel):
diff --git a/airflow-ctl/tests/airflow_ctl/api/test_operations.py 
b/airflow-ctl/tests/airflow_ctl/api/test_operations.py
index d745c777590..9b69e318fa2 100644
--- a/airflow-ctl/tests/airflow_ctl/api/test_operations.py
+++ b/airflow-ctl/tests/airflow_ctl/api/test_operations.py
@@ -444,6 +444,7 @@ class TestDagRunOperations:
     dag_id = "dag_id"
     dag_run_id = "dag_run_id"
     dag_run_response = DAGRunResponse(
+        dag_display_name=dag_run_id,
         dag_run_id=dag_run_id,
         dag_id=dag_id,
         logical_date=datetime.datetime(2025, 1, 1, 0, 0, 0),

Reply via email to