pierrejeambrun commented on code in PR #44624:
URL: https://github.com/apache/airflow/pull/44624#discussion_r1878347993
##########
airflow/api_fastapi/common/parameters.py:
##########
@@ -112,6 +112,34 @@ def depends(self, only_active: bool = True) ->
_OnlyActiveFilter:
return self.set_value(only_active)
+class _NoneFilter(BaseParam[bool]):
+ """check if a column is none or not."""
+
+ def __init__(self, attribute: ColumnElement, value: bool | None = None,
skip_none: bool = True) -> None:
+ super().__init__(value, skip_none)
+ self.attribute: ColumnElement = attribute
+ self.value: bool | None = value
+
+ def to_orm(self, select: Select) -> Select:
+ if not self.value and self.skip_none:
+ return select
+ return select.where(self.attribute.is_(None))
+
+ def depends(self, *args: Any, **kwargs: Any) -> Self:
+ raise NotImplementedError("Use search_param_factory instead , depends
is not implemented.")
+
+
+def none_param_factory(
+ attribute: ColumnElement,
+ none_filter_name: str,
+ skip_none: bool = True,
+) -> Callable[[bool | None], _NoneFilter]:
+ def depends_none(value: bool | None = Query(alias=none_filter_name,
default=None)) -> _NoneFilter:
Review Comment:
Maybe a more general approach is to `active=True` `active=False`
`active=None`.
- None is ignored and no filtering happen, returning all resources
- True, only take `active` ones, i.e end date is None
- False only take `inactive` ones, i.e end data is not None
This will allow retrieving only `inactive` backfills (which is not possible
at the moment and might be useful for other None filters), and without having
redundancy between `none` and `false` which are basically doing the same for
now.
##########
airflow/api_fastapi/common/parameters.py:
##########
@@ -112,6 +112,34 @@ def depends(self, only_active: bool = True) ->
_OnlyActiveFilter:
return self.set_value(only_active)
+class _NoneFilter(BaseParam[bool]):
+ """check if a column is none or not."""
+
+ def __init__(self, attribute: ColumnElement, value: bool | None = None,
skip_none: bool = True) -> None:
+ super().__init__(value, skip_none)
+ self.attribute: ColumnElement = attribute
+ self.value: bool | None = value
+
+ def to_orm(self, select: Select) -> Select:
+ if not self.value and self.skip_none:
+ return select
+ return select.where(self.attribute.is_(None))
+
+ def depends(self, *args: Any, **kwargs: Any) -> Self:
+ raise NotImplementedError("Use search_param_factory instead , depends
is not implemented.")
+
+
+def none_param_factory(
+ attribute: ColumnElement,
+ none_filter_name: str,
+ skip_none: bool = True,
+) -> Callable[[bool | None], _NoneFilter]:
+ def depends_none(value: bool | None = Query(alias=none_filter_name,
default=None)) -> _NoneFilter:
Review Comment:
Maybe a more general approach is to `active=True` `active=False`
`active=None`.
- None is ignored and no filtering happen, returning all resources
- True, only take `active` ones, i.e end date is None
- False only take `inactive` ones, i.e end data is not None
This will allow retrieving only `inactive` backfills (which is not possible
at the moment and might be useful for others _NoneFilter filters), and without
having redundancy between `none` and `false` which are basically doing the same
for now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]