Skip to content

Commit 7dc5c9a

Browse files
Fix no_status and duration for grid summaries
1 parent 9f04812 commit 7dc5c9a

File tree

4 files changed

+104
-19
lines changed

4 files changed

+104
-19
lines changed

airflow-core/src/airflow/api_fastapi/core_api/datamodels/ui/common.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from pydantic import computed_field
2424

2525
from airflow.api_fastapi.core_api.base import BaseModel
26+
from airflow.utils import timezone
2627
from airflow.utils.state import TaskInstanceState
2728
from airflow.utils.types import DagRunType
2829

@@ -81,9 +82,10 @@ class GridRunsResponse(BaseModel):
8182

8283
@computed_field
8384
def duration(self) -> int | None:
84-
if self.start_date and self.end_date:
85-
return (self.end_date - self.start_date).seconds
86-
return None
85+
if self.start_date:
86+
end_date = self.end_date or timezone.utcnow()
87+
return (end_date - self.start_date).seconds
88+
return 0
8789

8890

8991
class BaseGraphResponse(BaseModel, Generic[E, N]):

airflow-core/src/airflow/api_fastapi/core_api/routes/ui/grid.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,6 @@ def get_grid_runs(
480480
)
481481
),
482482
],
483-
response_model_exclude_none=True,
484483
)
485484
def get_grid_ti_summaries(
486485
dag_id: str,

airflow-core/src/airflow/api_fastapi/core_api/services/ui/grid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def agg_state(states):
326326

327327

328328
def _get_aggs_for_node(detail):
329-
states = [x["state"] for x in detail if x["state"] is not None]
329+
states = [x["state"] for x in detail]
330330
try:
331331
min_start_date = min(x["start_date"] for x in detail if x["start_date"])
332332
except ValueError:

airflow-core/tests/unit/api_fastapi/core_api/routes/ui/test_grid.py

Lines changed: 98 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,27 +1224,69 @@ def test_grid_ti_summaries_group(self, session, test_client):
12241224
"dag_id": "test_dag_4",
12251225
"run_id": "run_4-1",
12261226
"task_instances": [
1227-
{"state": "success", "task_id": "t1"},
1228-
{"state": "success", "task_id": "t2"},
1229-
{"state": "success", "task_id": "t7"},
1227+
{
1228+
"state": "success",
1229+
"task_id": "t1",
1230+
"child_states": None,
1231+
"max_end_date": None,
1232+
"min_start_date": None,
1233+
},
1234+
{
1235+
"state": "success",
1236+
"task_id": "t2",
1237+
"child_states": None,
1238+
"max_end_date": None,
1239+
"min_start_date": None,
1240+
},
1241+
{
1242+
"state": "success",
1243+
"task_id": "t7",
1244+
"child_states": None,
1245+
"max_end_date": None,
1246+
"min_start_date": None,
1247+
},
12301248
{
12311249
"child_states": {"success": 2},
12321250
"max_end_date": "2025-03-02T00:00:12Z",
12331251
"min_start_date": "2025-03-02T00:00:04Z",
12341252
"state": "success",
12351253
"task_id": "task_group-1",
12361254
},
1237-
{"state": "success", "task_id": "task_group-1.t6"},
1255+
{
1256+
"state": "success",
1257+
"task_id": "task_group-1.t6",
1258+
"child_states": None,
1259+
"max_end_date": None,
1260+
"min_start_date": None,
1261+
},
12381262
{
12391263
"child_states": {"success": 3},
12401264
"max_end_date": "2025-03-02T00:00:12Z",
12411265
"min_start_date": "2025-03-02T00:00:06Z",
12421266
"state": "success",
12431267
"task_id": "task_group-1.task_group-2",
12441268
},
1245-
{"state": "success", "task_id": "task_group-1.task_group-2.t3"},
1246-
{"state": "success", "task_id": "task_group-1.task_group-2.t4"},
1247-
{"state": "success", "task_id": "task_group-1.task_group-2.t5"},
1269+
{
1270+
"state": "success",
1271+
"task_id": "task_group-1.task_group-2.t3",
1272+
"child_states": None,
1273+
"max_end_date": None,
1274+
"min_start_date": None,
1275+
},
1276+
{
1277+
"state": "success",
1278+
"task_id": "task_group-1.task_group-2.t4",
1279+
"child_states": None,
1280+
"max_end_date": None,
1281+
"min_start_date": None,
1282+
},
1283+
{
1284+
"state": "success",
1285+
"task_id": "task_group-1.task_group-2.t5",
1286+
"child_states": None,
1287+
"max_end_date": None,
1288+
"min_start_date": None,
1289+
},
12481290
],
12491291
}
12501292
for obj in actual, expected:
@@ -1269,20 +1311,62 @@ def sort_dict(in_dict):
12691311
return out
12701312

12711313
expected = [
1272-
{"child_states": {}, "task_id": "mapped_task_2"},
1314+
{
1315+
"child_states": {},
1316+
"task_id": "mapped_task_2",
1317+
"max_end_date": None,
1318+
"min_start_date": None,
1319+
"state": None,
1320+
},
12731321
{
12741322
"child_states": {"running": 1},
12751323
"max_end_date": "2024-12-30T01:02:03Z",
12761324
"min_start_date": "2024-12-30T01:00:00Z",
12771325
"state": "running",
12781326
"task_id": "mapped_task_group",
12791327
},
1280-
{"state": "running", "task_id": "mapped_task_group.subtask"},
1281-
{"state": "success", "task_id": "task"},
1282-
{"child_states": {}, "task_id": "task_group"},
1283-
{"child_states": {}, "task_id": "task_group.inner_task_group"},
1284-
{"child_states": {}, "task_id": "task_group.inner_task_group.inner_task_group_sub_task"},
1285-
{"child_states": {}, "task_id": "task_group.mapped_task"},
1328+
{
1329+
"state": "running",
1330+
"task_id": "mapped_task_group.subtask",
1331+
"child_states": None,
1332+
"max_end_date": None,
1333+
"min_start_date": None,
1334+
},
1335+
{
1336+
"state": "success",
1337+
"task_id": "task",
1338+
"child_states": None,
1339+
"max_end_date": None,
1340+
"min_start_date": None,
1341+
},
1342+
{
1343+
"child_states": {},
1344+
"task_id": "task_group",
1345+
"max_end_date": None,
1346+
"min_start_date": None,
1347+
"state": None,
1348+
},
1349+
{
1350+
"child_states": {},
1351+
"task_id": "task_group.inner_task_group",
1352+
"max_end_date": None,
1353+
"min_start_date": None,
1354+
"state": None,
1355+
},
1356+
{
1357+
"child_states": {},
1358+
"task_id": "task_group.inner_task_group.inner_task_group_sub_task",
1359+
"max_end_date": None,
1360+
"min_start_date": None,
1361+
"state": None,
1362+
},
1363+
{
1364+
"child_states": {},
1365+
"task_id": "task_group.mapped_task",
1366+
"max_end_date": None,
1367+
"min_start_date": None,
1368+
"state": None,
1369+
},
12861370
]
12871371
expected = sort_dict(expected)
12881372
actual = sort_dict(actual)

0 commit comments

Comments
 (0)