Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from pydantic import computed_field

from airflow.api_fastapi.core_api.base import BaseModel
from airflow.utils import timezone
from airflow.utils.state import TaskInstanceState
from airflow.utils.types import DagRunType

Expand Down Expand Up @@ -81,9 +82,10 @@ class GridRunsResponse(BaseModel):

@computed_field
def duration(self) -> int | None:
if self.start_date and self.end_date:
return (self.end_date - self.start_date).seconds
return None
if self.start_date:
end_date = self.end_date or timezone.utcnow()
return (end_date - self.start_date).seconds
return 0


class BaseGraphResponse(BaseModel, Generic[E, N]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class LightGridTaskInstanceSummary(BaseModel):

task_id: str
state: TaskInstanceState | None
child_states: dict[TaskInstanceState, int] | None
child_states: dict[TaskInstanceState | None, int] | None
min_start_date: datetime | None
max_end_date: datetime | None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2122,8 +2122,6 @@ components:
anyOf:
- additionalProperties:
type: integer
propertyNames:
$ref: '#/components/schemas/TaskInstanceState'
type: object
- type: 'null'
title: Child States
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,6 @@ def get_grid_runs(
)
),
],
response_model_exclude_none=True,
)
def get_grid_ti_summaries(
dag_id: str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def agg_state(states):


def _get_aggs_for_node(detail):
states = [x["state"] for x in detail if x["state"] is not None]
states = [x["state"] for x in detail]
try:
min_start_date = min(x["start_date"] for x in detail if x["start_date"])
except ValueError:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7189,9 +7189,6 @@ export const $LightGridTaskInstanceSummary = {
additionalProperties: {
type: 'integer'
},
propertyNames: {
'$ref': '#/components/schemas/TaskInstanceState'
},
type: 'object'
},
{
Expand Down
112 changes: 98 additions & 14 deletions airflow-core/tests/unit/api_fastapi/core_api/routes/ui/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -1224,27 +1224,69 @@ def test_grid_ti_summaries_group(self, session, test_client):
"dag_id": "test_dag_4",
"run_id": "run_4-1",
"task_instances": [
{"state": "success", "task_id": "t1"},
{"state": "success", "task_id": "t2"},
{"state": "success", "task_id": "t7"},
{
"state": "success",
"task_id": "t1",
"child_states": None,
"max_end_date": None,
"min_start_date": None,
},
{
"state": "success",
"task_id": "t2",
"child_states": None,
"max_end_date": None,
"min_start_date": None,
},
{
"state": "success",
"task_id": "t7",
"child_states": None,
"max_end_date": None,
"min_start_date": None,
},
{
"child_states": {"success": 2},
"max_end_date": "2025-03-02T00:00:12Z",
"min_start_date": "2025-03-02T00:00:04Z",
"state": "success",
"task_id": "task_group-1",
},
{"state": "success", "task_id": "task_group-1.t6"},
{
"state": "success",
"task_id": "task_group-1.t6",
"child_states": None,
"max_end_date": None,
"min_start_date": None,
},
{
"child_states": {"success": 3},
"max_end_date": "2025-03-02T00:00:12Z",
"min_start_date": "2025-03-02T00:00:06Z",
"state": "success",
"task_id": "task_group-1.task_group-2",
},
{"state": "success", "task_id": "task_group-1.task_group-2.t3"},
{"state": "success", "task_id": "task_group-1.task_group-2.t4"},
{"state": "success", "task_id": "task_group-1.task_group-2.t5"},
{
"state": "success",
"task_id": "task_group-1.task_group-2.t3",
"child_states": None,
"max_end_date": None,
"min_start_date": None,
},
{
"state": "success",
"task_id": "task_group-1.task_group-2.t4",
"child_states": None,
"max_end_date": None,
"min_start_date": None,
},
{
"state": "success",
"task_id": "task_group-1.task_group-2.t5",
"child_states": None,
"max_end_date": None,
"min_start_date": None,
},
],
}
for obj in actual, expected:
Expand All @@ -1269,20 +1311,62 @@ def sort_dict(in_dict):
return out

expected = [
{"child_states": {}, "task_id": "mapped_task_2"},
{
"child_states": {"None": 1},
"task_id": "mapped_task_2",
"max_end_date": None,
"min_start_date": None,
"state": None,
},
{
"child_states": {"running": 1},
"max_end_date": "2024-12-30T01:02:03Z",
"min_start_date": "2024-12-30T01:00:00Z",
"state": "running",
"task_id": "mapped_task_group",
},
{"state": "running", "task_id": "mapped_task_group.subtask"},
{"state": "success", "task_id": "task"},
{"child_states": {}, "task_id": "task_group"},
{"child_states": {}, "task_id": "task_group.inner_task_group"},
{"child_states": {}, "task_id": "task_group.inner_task_group.inner_task_group_sub_task"},
{"child_states": {}, "task_id": "task_group.mapped_task"},
{
"state": "running",
"task_id": "mapped_task_group.subtask",
"child_states": None,
"max_end_date": None,
"min_start_date": None,
},
{
"state": "success",
"task_id": "task",
"child_states": None,
"max_end_date": None,
"min_start_date": None,
},
{
"child_states": {"None": 2},
"task_id": "task_group",
"max_end_date": None,
"min_start_date": None,
"state": None,
},
{
"child_states": {"None": 1},
"task_id": "task_group.inner_task_group",
"max_end_date": None,
"min_start_date": None,
"state": None,
},
{
"child_states": {"None": 2},
"task_id": "task_group.inner_task_group.inner_task_group_sub_task",
"max_end_date": None,
"min_start_date": None,
"state": None,
},
{
"child_states": {"None": 4},
"task_id": "task_group.mapped_task",
"max_end_date": None,
"min_start_date": None,
"state": None,
},
]
expected = sort_dict(expected)
actual = sort_dict(actual)
Expand Down