From f19ada67799d2a0e532123ff21f7cb9562e5391e Mon Sep 17 00:00:00 2001 From: Ephraim Anierobi Date: Fri, 28 Nov 2025 15:38:44 +0100 Subject: [PATCH] [v3-1-test] Fix incorrect backfill duration calculation in Grid view (#58813) The duration was calculated using timedelta.seconds which, returns only the seconds component, not the total duration. This caused backfills lasting more than a day to show incorrect durations. Changed to use total_seconds() which correctly returns the full duration. (cherry picked from commit acfcba15c8452fd4aad7ae85bc811df127252162) Co-authored-by: Ephraim Anierobi --- .../airflow/api_fastapi/core_api/datamodels/ui/common.py | 4 ++-- .../airflow/api_fastapi/core_api/openapi/_private_ui.yaml | 2 +- .../src/airflow/ui/openapi-gen/requests/schemas.gen.ts | 2 +- .../unit/api_fastapi/core_api/routes/ui/test_grid.py | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/airflow-core/src/airflow/api_fastapi/core_api/datamodels/ui/common.py b/airflow-core/src/airflow/api_fastapi/core_api/datamodels/ui/common.py index 2dee03e6510cc..6c96367da2e9b 100644 --- a/airflow-core/src/airflow/api_fastapi/core_api/datamodels/ui/common.py +++ b/airflow-core/src/airflow/api_fastapi/core_api/datamodels/ui/common.py @@ -81,10 +81,10 @@ class GridRunsResponse(BaseModel): run_type: DagRunType @computed_field - def duration(self) -> int: + def duration(self) -> float: if self.start_date: end_date = self.end_date or timezone.utcnow() - return (end_date - self.start_date).seconds + return (end_date - self.start_date).total_seconds() return 0 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 0d4aec6999728..7ff7310516432 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 @@ -1824,7 +1824,7 @@ components: run_type: $ref: '#/components/schemas/DagRunType' duration: - type: integer + type: number title: Duration readOnly: true type: object 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 3f0ebb2b82170..e45ee585988d8 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 @@ -7447,7 +7447,7 @@ export const $GridRunsResponse = { '$ref': '#/components/schemas/DagRunType' }, duration: { - type: 'integer', + type: 'number', title: 'Duration', readOnly: true } diff --git a/airflow-core/tests/unit/api_fastapi/core_api/routes/ui/test_grid.py b/airflow-core/tests/unit/api_fastapi/core_api/routes/ui/test_grid.py index 80f11a2c34155..4b0818dc1c543 100644 --- a/airflow-core/tests/unit/api_fastapi/core_api/routes/ui/test_grid.py +++ b/airflow-core/tests/unit/api_fastapi/core_api/routes/ui/test_grid.py @@ -58,7 +58,7 @@ GRID_RUN_1 = { "dag_id": "test_dag", - "duration": 0, + "duration": 283996800.0, "end_date": "2024-12-31T00:00:00Z", "run_after": "2024-11-30T00:00:00Z", "run_id": "run_1", @@ -69,7 +69,7 @@ GRID_RUN_2 = { "dag_id": "test_dag", - "duration": 0, + "duration": 283996800.0, "end_date": "2024-12-31T00:00:00Z", "run_after": "2024-11-30T00:00:00Z", "run_id": "run_2", @@ -528,7 +528,7 @@ def test_get_grid_runs(self, session, test_client): assert response.json() == [ { "dag_id": "test_dag", - "duration": 0, + "duration": 283996800.0, "end_date": "2024-12-31T00:00:00Z", "run_after": "2024-11-30T00:00:00Z", "run_id": "run_1", @@ -538,7 +538,7 @@ def test_get_grid_runs(self, session, test_client): }, { "dag_id": "test_dag", - "duration": 0, + "duration": 283996800.0, "end_date": "2024-12-31T00:00:00Z", "run_after": "2024-11-30T00:00:00Z", "run_id": "run_2",