as567-code opened a new pull request, #64163:
URL: https://github.com/apache/airflow/pull/64163
## Summary
The `/api/v2/dags/{dag_id}/tasks` endpoint crashes with `TypeError: '<' not
supported between instances of 'NoneType' and 'NoneType'` when sorting by
fields that can be `None` (e.g., `start_date` on unscheduled DAGs).
## Changes
**`airflow-core/src/airflow/api_fastapi/core_api/routes/public/tasks.py`:**
- Added upfront validation of `order_by` against known `TaskResponse` model
fields, returning HTTP 400 with a descriptive error listing valid field names
for invalid values
- Replaced `attrgetter` with a None-safe sort key `(value is None, value)`
that places `None` values last during sorting
- Extended exception handling to catch `TypeError` in addition to
`AttributeError`
**`airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_tasks.py`:**
- Updated existing invalid `order_by` test to match new error message format
- Added test for sorting unscheduled DAG tasks by `start_date` (where values
are `None`)
closes: #63927
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes — Claude Code (Opus 4.6)
Generated-by: Claude Code (Opus 4.6) following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
--
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]