uranusjr commented on code in PR #41307:
URL: https://github.com/apache/airflow/pull/41307#discussion_r1722832082
##########
airflow/api_connexion/endpoints/task_instance_endpoint.py:
##########
@@ -297,6 +279,31 @@ def _apply_range_filter(query: Select, key: ClauseElement,
value_range: tuple[T,
return query
+def _get_order_by_params(order_by: str | None = None) -> tuple:
+ """Return a tuple with the order by params to be used in the query."""
+ if order_by is None:
+ return (TI.map_index.asc(),)
+ if order_by == "state":
+ return (TI.state.asc(), TI.map_index.asc())
+ if order_by == "-state":
+ return (TI.state.desc(), TI.map_index.asc())
+ if order_by == "duration":
+ return (TI.duration.asc(), TI.map_index.asc())
+ if order_by == "-duration":
+ return (TI.duration.desc(), TI.map_index.asc())
+ if order_by == "start_date":
+ return (TI.start_date.asc(), TI.map_index.asc())
+ if order_by == "-start_date":
+ return (TI.start_date.desc(), TI.map_index.asc())
+ if order_by == "end_date":
+ return (TI.end_date.asc(), TI.map_index.asc())
+ if order_by == "-end_date":
+ return (TI.end_date.desc(), TI.map_index.asc())
+ if order_by == "-map_index":
+ return (TI.map_index.desc(),)
+ return ()
Review Comment:
If we receive an invalid value here, I think an error should just be raised
directly inside this function. Returning nothing is too easy for the call site
to not handle correctly.
--
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]