Skip to content

CLI: Add --limit flag to airflow dags list-runs - #71729

Merged
potiuk merged 1 commit into
apache:mainfrom
dkranchii:cli-dags-list-runs-limit
Sep 22, 2026
Merged

potiuk merged 1 commit into
apache:mainfrom
dkranchii:cli-dags-list-runs-limit

Conversation

@dkranchii

@dkranchii dkranchii commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

airflow dags list-jobs accepts --limit, but the sibling airflow dags list-runs command does not — on busy DAGs the command dumps every run since the start of time (subject to date filters). This PR closes that asymmetry with a small, additive flag.

Details

  • New ARG_DR_LIMIT typed as positive_int(allow_zero=False) — argparse rejects 0, negative numbers, and non-numeric input up-front.
  • Applied in dag_list_dag_runs after the existing run_after DESC sort, so --limit N reliably returns the N most recent runs regardless of insertion order in DagRun.find.
  • Default behaviour when the flag is absent is unchanged (all rows returned).

Test plan

  • ruff format and ruff check clean.
  • Parser smoke test: --limit 3 parses to int(3); --limit 0, --limit -1, --limit abc all rejected by argparse; --limit shows in dags list-runs --help.
  • uv run --project airflow-core pytest airflow-core/tests/unit/cli/commands/test_dag_command.py::TestCliDags::test_cli_list_dag_runs airflow-core/tests/unit/cli/commands/test_dag_command.py::TestCliDags::test_cli_list_dag_runs_limit airflow-core/tests/unit/cli/commands/test_dag_command.py::TestCliDags::test_cli_list_dag_runs_limit_rejects_invalid -xvs
  • prek run --from-ref main --stage pre-commit

Was generative AI tooling used to co-author this PR?
  • Yes — Cursor

@fat-catTW

Copy link
Copy Markdown
Contributor

Thanks!
This looks good overall.

Since this adds a user-facing airflow-core CLI option, could you add a newsfragment under airflow-core/newsfragments/, for example 71729.feature.rst or 71729.improvement.rst, mentioning the new airflow dags list-runs --limit option?

@dkranchii
dkranchii force-pushed the cli-dags-list-runs-limit branch from ee3e3c5 to f1f556d Compare August 18, 2026 17:39
@dkranchii
dkranchii force-pushed the cli-dags-list-runs-limit branch from f1f556d to 2e2bc0f Compare August 19, 2026 18:13
@fat-catTW

Copy link
Copy Markdown
Contributor

Awesome!!

@potiuk potiuk 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.

Thanks — small, well-scoped addition: argparse-level validation via positive_int(allow_zero=False) and slicing after the run_after DESC sort gives exactly the "N most recent runs" semantics. Approving.

A few non-blocking notes:

  • --limit caps the output, but DagRun.find still loads every matching run, so the database/memory cost on a busy Dag is unchanged. Fine for a CLI; just worth knowing if someone later wants to push the limit into the query.
  • test_cli_list_dag_runs_limit checks the returned rows are sorted, which a wrong-but-sorted subset would also satisfy. Asserting the run ids (e.g. --limit 1 → cli_limit_test_2) would pin the "most recent" part.
  • The newsfragment isn't required — AGENTS.md reserves airflow-core/newsfragments/ for major or breaking changes — but it does no harm; keep or drop as you prefer.

This review was drafted by an AI-assisted tool and
confirmed by an Apache Airflow maintainer. The maintainer
approving this PR has read the findings and signed off. If
something feels off, please reply on the PR and a maintainer
will follow up.

More on how Apache Airflow handles maintainer review:
contributing-docs/05_pull_requests.rst.


Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting

airflow dags list-jobs already accepts --limit but the neighbouring
list-runs command does not, so operators on busy DAGs have to pipe
through head or use date filters to shorten output. Mirroring the
existing flag closes that asymmetry and makes the two commands
predictable together.
@potiuk
potiuk force-pushed the cli-dags-list-runs-limit branch from 2e2bc0f to 07a8de9 Compare September 22, 2026 22:50
@potiuk
potiuk merged commit f081ffb into apache:main Sep 22, 2026
73 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants