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
54 changes: 41 additions & 13 deletions airflow-core/src/airflow/api_fastapi/common/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,10 @@ def to_orm(self, select: Select) -> Select:
class Range(BaseModel, Generic[T]):
"""Range with a lower and upper bound."""

lower_bound: T | None
upper_bound: T | None
lower_bound_gte: T | None
lower_bound_gt: T | None
upper_bound_lte: T | None
upper_bound_lt: T | None


class RangeFilter(BaseParam[Range]):
Expand All @@ -526,10 +528,18 @@ def to_orm(self, select: Select) -> Select:
if self.skip_none is False:
raise ValueError(f"Cannot set 'skip_none' to False on a {type(self)}")

if self.value and self.value.lower_bound:
select = select.where(self.attribute >= self.value.lower_bound)
if self.value and self.value.upper_bound:
select = select.where(self.attribute <= self.value.upper_bound)
if self.value is None:
return select

if self.value.lower_bound_gte:
select = select.where(self.attribute >= self.value.lower_bound_gte)
if self.value.lower_bound_gt:
select = select.where(self.attribute > self.value.lower_bound_gt)
if self.value.upper_bound_lte:
select = select.where(self.attribute <= self.value.upper_bound_lte)
if self.value.upper_bound_lt:
select = select.where(self.attribute < self.value.upper_bound_lt)

return select

@classmethod
Expand All @@ -539,22 +549,32 @@ def depends(cls, *args: Any, **kwargs: Any) -> Self:
def is_active(self) -> bool:
"""Check if the range filter has any active bounds."""
return self.value is not None and (
self.value.lower_bound is not None or self.value.upper_bound is not None
self.value.lower_bound_gte is not None
or self.value.lower_bound_gt is not None
or self.value.upper_bound_lte is not None
or self.value.upper_bound_lt is not None
)


def datetime_range_filter_factory(
filter_name: str, model: Base, attribute_name: str | None = None
) -> Callable[[datetime | None, datetime | None], RangeFilter]:
def depends_datetime(
lower_bound: datetime | None = Query(alias=f"{filter_name}_gte", default=None),
upper_bound: datetime | None = Query(alias=f"{filter_name}_lte", default=None),
lower_bound_gte: datetime | None = Query(alias=f"{filter_name}_gte", default=None),
lower_bound_gt: datetime | None = Query(alias=f"{filter_name}_gt", default=None),
upper_bound_lte: datetime | None = Query(alias=f"{filter_name}_lte", default=None),
upper_bound_lt: datetime | None = Query(alias=f"{filter_name}_lt", default=None),
) -> RangeFilter:
attr = getattr(model, attribute_name or filter_name)
if filter_name in ("start_date", "end_date"):
attr = func.coalesce(attr, func.now())
return RangeFilter(
Range(lower_bound=lower_bound, upper_bound=upper_bound),
Range(
lower_bound_gte=lower_bound_gte,
lower_bound_gt=lower_bound_gt,
upper_bound_lte=upper_bound_lte,
upper_bound_lt=upper_bound_lt,
),
attr,
)

Expand All @@ -565,11 +585,19 @@ def float_range_filter_factory(
filter_name: str, model: Base
) -> Callable[[float | None, float | None], RangeFilter]:
def depends_float(
lower_bound: float | None = Query(alias=f"{filter_name}_gte", default=None),
upper_bound: float | None = Query(alias=f"{filter_name}_lte", default=None),
lower_bound_gte: float | None = Query(alias=f"{filter_name}_gte", default=None),
lower_bound_gt: float | None = Query(alias=f"{filter_name}_gt", default=None),
upper_bound_lte: float | None = Query(alias=f"{filter_name}_lte", default=None),
upper_bound_lt: float | None = Query(alias=f"{filter_name}_lt", default=None),
) -> RangeFilter:
return RangeFilter(
Range(lower_bound=lower_bound, upper_bound=upper_bound), getattr(model, filter_name)
Range(
lower_bound_gte=lower_bound_gte,
lower_bound_gt=lower_bound_gt,
upper_bound_lte=upper_bound_lte,
upper_bound_lt=upper_bound_lt,
),
getattr(model, filter_name),
)

return depends_float
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,23 @@ class DAGRunsBatchBody(StrictBaseModel):
page_limit: NonNegativeInt = 100
dag_ids: list[str] | None = None
states: list[DagRunState | None] | None = None

run_after_gte: AwareDatetime | None = None
run_after_gt: AwareDatetime | None = None
run_after_lte: AwareDatetime | None = None
run_after_lt: AwareDatetime | None = None

logical_date_gte: AwareDatetime | None = None
logical_date_gt: AwareDatetime | None = None
logical_date_lte: AwareDatetime | None = None
logical_date_lt: AwareDatetime | None = None

start_date_gte: AwareDatetime | None = None
start_date_gt: AwareDatetime | None = None
start_date_lte: AwareDatetime | None = None
start_date_lt: AwareDatetime | None = None

end_date_gte: AwareDatetime | None = None
end_date_gt: AwareDatetime | None = None
end_date_lte: AwareDatetime | None = None
end_date_lt: AwareDatetime | None = None
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,32 @@ class TaskInstancesBatchBody(StrictBaseModel):
dag_run_ids: list[str] | None = None
task_ids: list[str] | None = None
state: list[TaskInstanceState | None] | None = None

run_after_gte: AwareDatetime | None = None
run_after_gt: AwareDatetime | None = None
run_after_lte: AwareDatetime | None = None
run_after_lt: AwareDatetime | None = None

logical_date_gte: AwareDatetime | None = None
logical_date_gt: AwareDatetime | None = None
logical_date_lte: AwareDatetime | None = None
logical_date_lt: AwareDatetime | None = None

start_date_gte: AwareDatetime | None = None
start_date_gt: AwareDatetime | None = None
start_date_lte: AwareDatetime | None = None
start_date_lt: AwareDatetime | None = None

end_date_gte: AwareDatetime | None = None
end_date_gt: AwareDatetime | None = None
end_date_lte: AwareDatetime | None = None
end_date_lt: AwareDatetime | None = None

duration_gte: float | None = None
duration_gt: float | None = None
duration_lte: float | None = None
duration_lt: float | None = None

pool: list[str] | None = None
queue: list[str] | None = None
executor: list[str] | None = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,15 @@ paths:
format: date-time
- type: 'null'
title: Run After Gte
- name: run_after_gt
in: query
required: false
schema:
anyOf:
- type: string
format: date-time
- type: 'null'
title: Run After Gt
- name: run_after_lte
in: query
required: false
Expand All @@ -606,6 +615,15 @@ paths:
format: date-time
- type: 'null'
title: Run After Lte
- name: run_after_lt
in: query
required: false
schema:
anyOf:
- type: string
format: date-time
- type: 'null'
title: Run After Lt
responses:
'200':
description: Successful Response
Expand Down Expand Up @@ -686,6 +704,15 @@ paths:
format: date-time
- type: 'null'
title: Run After Gte
- name: run_after_gt
in: query
required: false
schema:
anyOf:
- type: string
format: date-time
- type: 'null'
title: Run After Gt
- name: run_after_lte
in: query
required: false
Expand All @@ -695,6 +722,15 @@ paths:
format: date-time
- type: 'null'
title: Run After Lte
- name: run_after_lt
in: query
required: false
schema:
anyOf:
- type: string
format: date-time
- type: 'null'
title: Run After Lt
responses:
'200':
description: Successful Response
Expand Down Expand Up @@ -830,6 +866,15 @@ paths:
format: date-time
- type: 'null'
title: Logical Date Gte
- name: logical_date_gt
in: query
required: false
schema:
anyOf:
- type: string
format: date-time
- type: 'null'
title: Logical Date Gt
- name: logical_date_lte
in: query
required: false
Expand All @@ -839,6 +884,15 @@ paths:
format: date-time
- type: 'null'
title: Logical Date Lte
- name: logical_date_lt
in: query
required: false
schema:
anyOf:
- type: string
format: date-time
- type: 'null'
title: Logical Date Lt
responses:
'200':
description: Successful Response
Expand Down
Loading
Loading