Skip to content

Fix GET tasks endpoint crash when sorting by attributes with None values#64320

Closed
syhstanley wants to merge 2 commits into
apache:mainfrom
syhstanley:fix/task-order-by-null-safe-63927
Closed

Fix GET tasks endpoint crash when sorting by attributes with None values#64320
syhstanley wants to merge 2 commits into
apache:mainfrom
syhstanley:fix/task-order-by-null-safe-63927

Conversation

@syhstanley

@syhstanley syhstanley commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

closes: #63927

The GET /api/v2/dags/{dag_id}/tasks endpoint raises a TypeError when
sorting tasks by attributes that contain None values (e.g. start_date
on unscheduled DAGs), because Python cannot compare None with other types.

Changes:

  • Add a null-safe sort_key function inside get_tasks that uses tuple
    comparison to place None values last on ascending sort and first on
    descending sort, matching default PostgreSQL NULLS LAST / NULLS FIRST
    behaviour.
  • Add a test_mixed_start_date_dag test DAG with mixed None and non-None
    start_date values.
  • Add test cases for:
    • Ascending/descending sort with all-None values
    • Ascending/descending sort with mixed None/non-None values (verifies actual ordering)
    • Ascending/descending sort by task_id

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Claude Code following the guidelines

The GET /api/v2/dags/{dag_id}/tasks endpoint raises a TypeError when
sorting by attributes like start_date that contain None values
(e.g. unscheduled DAGs). Add a null-safe sort key inside get_tasks
that places None values last on ascending and first on descending,
matching default PostgreSQL behaviour.

Closes: apache#63927

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

@pierrejeambrun pierrejeambrun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing in favor of #64384

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/dags/{dag_id}/tasks improper null handling for order_by

3 participants