tysoncung opened a new pull request, #63991:
URL: https://github.com/apache/airflow/pull/63991

   ## Problem
   
   Calling `/api/v2/dags/{dag_id}/tasks?order_by=start_date` causes a 500 
Internal Server Error:
   
   ```
   TypeError: '<' not supported between instances of 'NoneType' and 'NoneType'
   ```
   
   This happens because task attributes like `start_date` can be `None`, and 
Python's `sorted()` cannot compare `None` values using `<`.
   
   ## Solution
   
   Introduced a sort key function that:
   1. Uses a tuple `(val is None, val)` to ensure `None` values sort to the end
   2. Falls back to an empty string for `None` to avoid comparison errors
   3. Works correctly for both ascending and descending sort directions
   
   ## Files Changed
   
   - `airflow-core/src/airflow/api_fastapi/core_api/routes/public/tasks.py`
   
   ## Testing
   
   - `GET /api/v2/dags/{dag_id}/tasks?order_by=start_date` → returns tasks 
sorted with None values at the end (previously 500)
   - `GET /api/v2/dags/{dag_id}/tasks?order_by=-start_date` → returns tasks 
reverse-sorted with None values at the end
   - `GET /api/v2/dags/{dag_id}/tasks?order_by=task_id` → unchanged behavior 
(no None values)
   - `GET /api/v2/dags/{dag_id}/tasks?order_by=invalid_field` → still returns 
400 Bad Request
   
   Closes #63927


-- 
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]

Reply via email to