Skip to content

fix: pass order_by to Airflow API params in list adapters#230

Open
de-harish wants to merge 3 commits into
astronomer:mainfrom
de-harish:fix/adapter-order-by-defaults
Open

fix: pass order_by to Airflow API params in list adapters#230
de-harish wants to merge 3 commits into
astronomer:mainfrom
de-harish:fix/adapter-order-by-defaults

Conversation

@de-harish

Copy link
Copy Markdown

What

list_dag_runs, get_task_instances, list_asset_events, and list_import_errors in both adapters (airflow_v2.py and airflow_v3.py) were building params dicts without including order_by. The sort parameter was silently dropped even when explicitly passed by callers — for example, dag_run.py already exposed order_by="-start_date" on the tool but the adapter discarded it before the HTTP call.

Why

The Airflow REST API defaults to ascending order when no order_by is provided, so all list tools were returning oldest-first regardless of what the caller requested.

Changes

Added order_by to each endpoint's params dict with sensible defaults so results are returned newest-first out of the box:

Method Default
list_dag_runs -start_date
get_task_instances -start_date
list_asset_events -timestamp
list_import_errors -import_error_id

Testing

  • Ruff lint and format both pass (uvx ruff check and uvx ruff format --check)
  • Existing tests in test_adapters.py continue to pass (no assertions on order_by param needed changing)

list_dag_runs, get_task_instances, list_asset_events, and
list_import_errors were building params dicts without order_by,
so the sort parameter was silently dropped even when callers passed it.

Add order_by to each endpoint's params dict with sensible defaults
so results are returned newest-first out of the box:
- list_dag_runs / get_task_instances: -start_date
- list_asset_events: -timestamp
- list_import_errors: -import_error_id
/datasets/events and /assets/events do not support order_by — passing it
causes a 400 Bad Request. Removed order_by from those API params; Airflow
already returns asset events newest-first by default.

/importErrors also does not support order_by. Switched to client-side
sorting after fetching results so the default (-import_error_id) still
gives most-recent-first behaviour without breaking the API call.
list_dags now accepts order_by, tags, dag_id_pattern, only_active and
paused parameters so callers can filter and sort without post-processing.

list_dag_runs now accepts state, start_date_gte and start_date_lte
filters so callers can narrow to failed/running runs or a specific time
window without fetching the full history.

Abstract base updated to match both concrete adapters (v2, v3).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant