uranusjr commented on a change in pull request #14895:
URL: https://github.com/apache/airflow/pull/14895#discussion_r599164667
##########
File path: airflow/api_connexion/endpoints/task_endpoint.py
##########
@@ -49,11 +51,21 @@ def get_task(dag_id, task_id):
(permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE),
]
)
-def get_tasks(dag_id):
+def get_tasks(dag_id, order_by='task_id'):
"""Get tasks for DAG"""
dag: DAG = current_app.dag_bag.get_dag(dag_id)
if not dag:
raise NotFound("DAG not found")
tasks = dag.tasks
+ if '-' in order_by:
+ try:
+ tasks = sorted(tasks, key=attrgetter(order_by.strip('-')),
reverse=True)
+ except AttributeError as err:
+ raise BadRequest(detail=str(err))
+ else:
+ try:
+ tasks = sorted(tasks, key=attrgetter(order_by))
+ except AttributeError as err:
+ raise BadRequest(detail=str(err))
Review comment:
Maybe `order_by.lstrip('-')` and `reverse=(orderby[0] == '-')` instead?
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]