pierrejeambrun commented on code in PR #63991:
URL: https://github.com/apache/airflow/pull/63991#discussion_r2996383592
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/tasks.py:
##########
@@ -53,7 +53,15 @@ def get_tasks(
"""Get tasks for DAG."""
dag = get_latest_version_of_dag(dag_bag, dag_id, session)
try:
- tasks = sorted(dag.tasks, key=attrgetter(order_by.lstrip("-")),
reverse=(order_by[0:1] == "-"))
+ attr_name = order_by.lstrip("-")
+ reverse = order_by[0:1] == "-"
+
+ def _sort_key(task):
+ val = attrgetter(attr_name)(task)
+ # Place None values at the end regardless of sort direction
+ return (val is None, val if val is not None else "")
Review Comment:
+1 this should be simplified.
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/tasks.py:
##########
@@ -53,7 +53,15 @@ def get_tasks(
"""Get tasks for DAG."""
dag = get_latest_version_of_dag(dag_bag, dag_id, session)
try:
- tasks = sorted(dag.tasks, key=attrgetter(order_by.lstrip("-")),
reverse=(order_by[0:1] == "-"))
+ attr_name = order_by.lstrip("-")
+ reverse = order_by[0:1] == "-"
+
+ def _sort_key(task):
+ val = attrgetter(attr_name)(task)
+ # Place None values at the end regardless of sort direction
Review Comment:
Can we not put None always last?
For other endpoints we fallback to the db backend nulls default ordering.
Can we do the same please.
--
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]