Stable REST API list endpoint returns fewer items than the requested limit
0 reputation · 04 Jan 2021, 10:41 UTC
0 reputation · 04 Jan 2021, 10:41 UTC
We are exporting a large set of DAG runs and task instances through the Airflow Stable REST API (2.x, /api/v1/dags/{dag_id}/dagRuns and /api/v1/dags/{dag_id}/taskInstances). Our client requests a page size via the limit parameter and advances offset until the result set is exhausted.
When the requested limit exceeds the [api] maximum_page_limit setting in airflow.cfg, the response appears to contain fewer items than requested, without an error. Our pagination loop treats a short page as end-of-data, so the export silently truncates. The response does include total_entries, but we are unsure whether the cap is applied silently on every endpoint or whether some versions reject oversized limits instead.
limit always clamped silently to maximum_page_limit, or does behavior differ by endpoint or Airflow minor version?total_entries once and stepping offset by the effective page size the documented-safe loop, given that task instance states change between calls?order_by with offset paging or filtered time windows, and does Airflow 3.x (/api/v2) change any of this?34775 reputation · 04 Jan 2021, 16:06 UTC
Your export is truncating because Airflow REST API v1 silently clamps any client-supplied limit to the [api] maximum_page_limit value in airflow.cfg. When you request a limit larger than the cap, the endpoint returns fewer items than requested with no error, and your loop treats that short page as end-of-data.
maximum_page_limit and does so silently. The response contains a smaller items array and no error.total_entries is computed at query time per request. It is not stable for mutable tables. DAG runs and task instances can be created or updated between pages, so total_entries drifts./api/v2. Pagination defaults, limit enforcement and response shape change, so v1 behavior does not transfer to 3.x./api/v1/dags/{dag_id}/dagRuns and /api/v1/dags/{dag_id}/taskInstances. In practice the silent clamp is consistent across those list endpoints in Airflow 2.x, though exact enforcement points and defaults are version-sensitive between 2.2-2.10.total_entries once and stepping offset by an assumed page size is not safe.limit larger than you expect, e.g. limit=10000, and compare the returned items length to the request. Inspect airflow.cfg [api] maximum_page_limit on the server.len(items) < effective_limit.order_by on immutable columns, e.g. execution_date and run_id for dagRuns, and a comparable stable ordering for taskInstances. Terminate only on an empty page, not on offset >= total_entries.execution_date window and advance the window after each complete pass, rather than relying on a global offset.One diagnostic detail that changes the recommendation: what Airflow minor version are you running and what is the current [api] maximum_page_limit value? The default and enforcement point vary across 2.2-2.10, and the safe page size and response fields differ for /api/v2 in Airflow 3.x.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.