dstandish commented on code in PR #44226:
URL: https://github.com/apache/airflow/pull/44226#discussion_r1852105081
##########
airflow/api_fastapi/common/db/common.py:
##########
@@ -47,40 +52,45 @@ def your_route(session: Annotated[Session,
Depends(get_session)]):
yield session
-def apply_filters_to_select(base_select: Select, filters: Sequence[BaseParam |
None]) -> Select:
- base_select = base_select
- for filter in filters:
- if filter is None:
+def apply_filters_to_select(
+ *, base_select: Select, filters: Sequence[BaseParam | None] | None = None
+) -> Select:
+ if filters is None:
+ return base_select
+ for f in filters:
+ if f is None:
continue
- base_select = filter.to_orm(base_select)
+ base_select = f.to_orm(base_select)
return base_select
@provide_session
def paginated_select(
base_select: Select,
- filters: Sequence[BaseParam],
+ filters: Sequence[BaseParam] | None = None,
order_by: BaseParam | None = None,
offset: BaseParam | None = None,
limit: BaseParam | None = None,
session: Session = NEW_SESSION,
return_total_entries: bool = True,
-) -> Select:
+) -> tuple[Select, int | None]:
base_select = apply_filters_to_select(
- base_select,
- filters,
+ base_select=base_select,
+ filters=filters,
)
total_entries = None
if return_total_entries:
total_entries = get_query_count(base_select, session=session)
+ if TYPE_CHECKING:
+ assert isinstance(total_entries, int)
Review Comment:
if you look at the signature of paginated_select, note that i fixed it -- it
used to say `-> Select` but now i say `-> tuple[Select, int | None]`. This is
why the typing shenanigans are required. If we remove possible optionality of
the count, then this would not be necessary.
I think the count optionality was added recently.
--
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]