pierrejeambrun commented on code in PR #42782:
URL: https://github.com/apache/airflow/pull/42782#discussion_r1793595097
##########
airflow/api_fastapi/parameters.py:
##########
@@ -171,7 +180,10 @@ def to_orm(self, select: Select) -> Select:
f"the attribute does not exist on the model",
)
- column = self.attr_mapping.get(lstriped_orderby, None) or
getattr(DagModel, lstriped_orderby)
+ if self.to_replace:
+ lstriped_orderby = self.to_replace.get(lstriped_orderby,
lstriped_orderby)
+
+ column = self.attr_mapping.get(lstriped_orderby, None) or
getattr(self.model, lstriped_orderby)
Review Comment:
We use it only here, and that's the attribute ? I would say.
##########
airflow/api_fastapi/parameters.py:
##########
@@ -171,7 +180,10 @@ def to_orm(self, select: Select) -> Select:
f"the attribute does not exist on the model",
)
- column = self.attr_mapping.get(lstriped_orderby, None) or
getattr(DagModel, lstriped_orderby)
+ if self.to_replace:
+ lstriped_orderby = self.to_replace.get(lstriped_orderby,
lstriped_orderby)
Review Comment:
I think we can get rid of the `to_replace`. It adds extra complexity for
mapping things to gether. We can just rename to use the appropriate one. No
need to remap. i.e `conn_id`. Or again find a way to always just use the
mapping. So we have only 1 ugly mapping and everything uses that to retrieve
the `db/model` equivalent.
##########
airflow/api_fastapi/parameters.py:
##########
@@ -144,17 +146,24 @@ def depends(self, dag_display_name_pattern: str | None =
None) -> _DagDisplayNam
return self.set_value(dag_display_name_pattern)
+# SortParam Implementations
class SortParam(BaseParam[str]):
"""Order result by the attribute."""
- attr_mapping = {
- "last_run_state": DagRun.state,
- "last_run_start_date": DagRun.start_date,
- }
-
- def __init__(self, allowed_attrs: list[str]) -> None:
+ def __init__(
+ self,
+ allowed_attrs: list[str],
+ attr_mapping: dict[str, Any],
+ model: type[BaseModel],
+ order_column: Column,
+ to_replace: dict[str, str] | None,
+ ) -> None:
super().__init__()
self.allowed_attrs = allowed_attrs
+ self.attr_mapping = attr_mapping
+ self.model = model
Review Comment:
I'm not sure why you need an extra `model`. Can't we use the `attr_mapping`
? That already gives the appropriate model+column ?
--
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]