Skip to content

Fix airflow dags list-jobs --limit to reject non-numeric values - #73105

Closed
roykoand wants to merge 3 commits into
apache:mainfrom
roykoand:fix-dags-list-jobs-limit-validation
Closed

roykoand wants to merge 3 commits into
apache:mainfrom
roykoand:fix-dags-list-jobs-limit-validation

Conversation

@roykoand

Copy link
Copy Markdown
Contributor

ARG_LIMIT (used by airflow dags list-jobs --limit) had no type= validation, unlike its siblings ARG_JOB_LIMIT and ARG_NUM_EXECUTIONS, which both use type=positive_int(...). A non-numeric --limit value (e.g. airflow dags list-jobs --limit abc) was passed through argparse as a raw string and crashed deep inside SQLAlchemy's limit-clause coercion with an unhandled ValueError/traceback, instead of the standard argparse usage error every other typed numeric flag produces.

This adds the same type=positive_int(allow_zero=False) to ARG_LIMIT, plus a regression test asserting --limit abc now exits with argparse's usage-error code (2) instead of crashing.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Sonnet 5)

Generated-by: Claude Code (Sonnet 5) following the guidelines

🤖 Generated with Claude Code

ARG_LIMIT had no type validation, unlike its siblings ARG_JOB_LIMIT and
ARG_NUM_EXECUTIONS, so a non-numeric --limit value crashed deep inside
SQLAlchemy's limit-clause coercion with a raw traceback instead of a
clean argparse usage error.

@Vamsi-klu Vamsi-klu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment thread airflow-core/src/airflow/cli/cli_config.py
The previous fix rejected --limit 0 along with non-numeric and
negative values, but 0 was a valid (if unusual) prior invocation --
SQLAlchemy coerced it to LIMIT 0, an intentional "return no records"
query, distinct from the undefined behavior of a negative limit.
0 has no documented meaning for this flag, unlike the differently-scoped
ARG_JOB_LIMIT ("0 disables the limit"). Returning zero records isn't a
useful query here -- it's the same "how many things to show" category as
ARG_NUM_EXECUTIONS/ARG_CAPACITY, which also disallow zero.

Also consolidates the invalid-limit regression tests (non-numeric,
negative, zero) into a single parametrized test.
Comment thread airflow-core/src/airflow/cli/cli_config.py
@roykoand
roykoand marked this pull request as ready for review September 14, 2026 06:26
@roykoand

Copy link
Copy Markdown
Contributor Author

Well, did not notice the same issue was already surfaced - #72891

@roykoand roykoand closed this Sep 15, 2026
@roykoand
roykoand deleted the fix-dags-list-jobs-limit-validation branch September 15, 2026 18:17
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.

2 participants