Skip to content

Commit 2c77a66

Browse files
committed
Allow 'no_status' state filter and include no_status in valid state list; skip date filters when filtering for null state
1 parent 8fbb03f commit 2c77a66

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

airflow-core/src/airflow/api_fastapi/core_api/routes/public/task_instances.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
from __future__ import annotations
1919

20-
from typing import Annotated, Literal, cast
20+
from collections.abc import Sequence
21+
from typing import Annotated, Any, Literal, cast
2122

2223
import structlog
2324
from fastapi import Depends, HTTPException, Query, status
@@ -49,6 +50,7 @@
4950
float_range_filter_factory,
5051
)
5152
from airflow.api_fastapi.common.router import AirflowRouter
53+
from airflow.api_fastapi.core_api.base import OrmClause
5254
from airflow.api_fastapi.core_api.datamodels.common import BulkBody, BulkResponse
5355
from airflow.api_fastapi.core_api.datamodels.task_instances import (
5456
BulkTaskInstanceBody,
@@ -194,9 +196,10 @@ def get_mapped_task_instances(
194196
error_message = f"Task id {task_id} is not mapped"
195197
raise HTTPException(status.HTTP_404_NOT_FOUND, error_message)
196198

197-
task_instance_select, total_entries = paginated_select(
198-
statement=query,
199-
filters=[
199+
if state.value is not None and None in state.value:
200+
filters = [state, pool, queue, executor, version_number]
201+
else:
202+
filters = [
200203
run_after_range,
201204
logical_date_range,
202205
start_date_range,
@@ -208,7 +211,10 @@ def get_mapped_task_instances(
208211
queue,
209212
executor,
210213
version_number,
211-
],
214+
]
215+
task_instance_select, total_entries = paginated_select(
216+
statement=query,
217+
filters=cast("Sequence[OrmClause[Any]]", filters),
212218
order_by=order_by,
213219
offset=offset,
214220
limit=limit,
@@ -460,9 +466,19 @@ def get_task_instances(
460466
)
461467
query = query.where(TI.run_id == dag_run_id)
462468

463-
task_instance_select, total_entries = paginated_select(
464-
statement=query,
465-
filters=[
469+
if state.value is not None and None in state.value:
470+
filters = [
471+
state,
472+
pool,
473+
queue,
474+
executor,
475+
task_id,
476+
task_display_name_pattern,
477+
version_number,
478+
readable_ti_filter,
479+
]
480+
else:
481+
filters = [
466482
run_after_range,
467483
logical_date_range,
468484
start_date_range,
@@ -477,7 +493,10 @@ def get_task_instances(
477493
task_display_name_pattern,
478494
version_number,
479495
readable_ti_filter,
480-
],
496+
]
497+
task_instance_select, total_entries = paginated_select(
498+
statement=query,
499+
filters=cast("Sequence[OrmClause[Any]]", filters),
481500
order_by=order_by,
482501
offset=offset,
483502
limit=limit,

0 commit comments

Comments
 (0)