pierrejeambrun commented on code in PR #47440:
URL: https://github.com/apache/airflow/pull/47440#discussion_r2020608835
##########
airflow-core/src/airflow/api_fastapi/common/parameters.py:
##########
@@ -221,9 +246,13 @@ def get_primary_key_string(self) -> str:
def depends(cls, *args: Any, **kwargs: Any) -> Self:
raise NotImplementedError("Use dynamic_depends, depends not
implemented.")
- def dynamic_depends(self, default: str | None = None) -> Callable:
- def inner(order_by: str = default or self.get_primary_key_string()) ->
SortParam:
- return self.set_value(self.get_primary_key_string() if order_by ==
"" else order_by)
+ def dynamic_depends(self, default: list[str] | None = None) -> Callable:
+ def inner(order_by: list[str] | str | None = Query(default)) ->
SortParam:
+ if order_by is None:
+ order_by = [self.get_primary_key_string()]
+ elif isinstance(order_by, str):
+ order_by = [order_by]
+ return self.set_value(order_by)
Review Comment:
I'm not sure it's exactly equivalent. If there is no `order_by` query param
specified, we shouldn't add any by default and let the query default order
operate. (default is None).
If there is an empty list or values that are empty string, then I think we
should replace with `self.get_primary_key_string()]
##########
airflow-core/src/airflow/api_fastapi/common/parameters.py:
##########
@@ -171,43 +171,68 @@ def __init__(
self.to_replace = to_replace
def to_orm(self, select: Select) -> Select:
+ MAX_SORT_PARAMS = 5
Review Comment:
I think the limit should be made greater.
We already have table with more than 5 columns and the UI could reach that
pretty soon.
Going for 10 or 20 shouldn't hurt. (all our different db should be able to
handle much more anyway)
##########
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dags.py:
##########
@@ -230,6 +230,22 @@ class TestGetDags(TestDagEndpoint):
3,
[DAG3_ID, DAG1_ID, DAG2_ID],
),
+ ({"order_by": ["last_run_state", "dag_display_name"],
"only_active": False}, 3, [DAG1_ID, DAG3_ID, DAG2_ID]),
+ ({"order_by": ["-last_run_state", "dag_display_name"],
"only_active": False}, 3, [DAG3_ID, DAG1_ID, DAG2_ID]),
+ ({"order_by": ["last_run_start_date", "dag_display_name"],
"only_active": False}, 3, [DAG1_ID, DAG3_ID, DAG2_ID]),
+ ({"order_by": ["-last_run_start_date", "dag_display_name"],
"only_active": False}, 3, [DAG3_ID, DAG1_ID, DAG2_ID]),
+ ({"order_by": ["-dag_id", "dag_display_name"]}, 2, [DAG2_ID,
DAG1_ID]),
+ ({"order_by": ["dag_id", "dag_display_name"]}, 2, [DAG1_ID,
DAG2_ID]),
+ ({"order_by": ["dag_display_name", "dag_id"]}, 2, [DAG1_ID,
DAG2_ID]),
+ ({"order_by": ["last_run_state"], "only_active": False}, 3,
[DAG1_ID, DAG3_ID, DAG2_ID]),
+ ({"order_by": ["-last_run_state"], "only_active": False}, 3,
[DAG3_ID, DAG1_ID, DAG2_ID]),
+ ({"order_by": ["last_run_start_date"], "only_active": False}, 3,
[DAG1_ID, DAG3_ID, DAG2_ID]),
+ ({"order_by": ["-last_run_start_date"], "only_active": False}, 3,
[DAG3_ID, DAG1_ID, DAG2_ID])
+
+ ({"order_by": ["dag_display_name", "-next_dagrun"]}, 2, [DAG1_ID,
DAG2_ID]),
+ ({"order_by": ["last_run_state", "-dag_display_name", "dag_id"]},
2, [DAG1_ID, DAG2_ID]),
+ ({"order_by": ["-last_run_start_date", "dag_display_name",
"next_dagrun", "dag_id"]}, 2, [ DAG1_ID, DAG2_ID]),
+ ({"order_by": ["dag_display_name", "-last_run_state",
"next_dagrun", "dag_id", "last_run_start_date"]}, 2, [DAG1_ID, DAG2_ID]),
Review Comment:
We still need two tests with:
```
({"order_by": ["criteria_1", "criteria_2"]}, 2, [id1, id2, id3]),
({"order_by": ["criteria_1", "-criteria_2"]}, 2, [different
sequence of id, proving that criteria_2 is being considerd]),
```
##########
airflow-core/src/airflow/api_fastapi/common/parameters.py:
##########
@@ -221,9 +246,13 @@ def get_primary_key_string(self) -> str:
def depends(cls, *args: Any, **kwargs: Any) -> Self:
raise NotImplementedError("Use dynamic_depends, depends not
implemented.")
- def dynamic_depends(self, default: str | None = None) -> Callable:
- def inner(order_by: str = default or self.get_primary_key_string()) ->
SortParam:
- return self.set_value(self.get_primary_key_string() if order_by ==
"" else order_by)
+ def dynamic_depends(self, default: list[str] | None = None) -> Callable:
+ def inner(order_by: list[str] | str | None = Query(default)) ->
SortParam:
+ if order_by is None:
+ order_by = [self.get_primary_key_string()]
+ elif isinstance(order_by, str):
+ order_by = [order_by]
Review Comment:
This shouldn't be possible. FastAPI validation will prevent such wrong input
and will do what's necessary to either get a `list[str]` or fail with a 422
validation error if not possible.
--
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]