From 0943767ddd7960b8c0d7a18aab5b306f6c45d4f7 Mon Sep 17 00:00:00 2001 From: Eason09053360 <185830721+Eason09053360@users.noreply.github.com> Date: Thu, 10 Sep 2026 22:50:04 +0800 Subject: [PATCH] Reject non-numeric --limit values in airflow dags list-jobs The --limit option had no argparse type, so a value such as "abc" or "-1" was passed straight into the SQLAlchemy query and surfaced as a raw ValueError traceback instead of a usage error. Validating it at parse time gives the standard argparse message and exit code 2, while keeping 0 and positive integers working exactly as before. --- airflow-core/src/airflow/cli/cli_config.py | 2 +- airflow-core/tests/unit/cli/test_cli_parser.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/airflow-core/src/airflow/cli/cli_config.py b/airflow-core/src/airflow/cli/cli_config.py index 9ab2d84a33165..db1099398e766 100644 --- a/airflow-core/src/airflow/cli/cli_config.py +++ b/airflow-core/src/airflow/cli/cli_config.py @@ -294,7 +294,7 @@ def string_lower_type(val): # list_jobs ARG_DAG_ID_OPT = Arg(("-d", "--dag-id"), help="The id of the dag") -ARG_LIMIT = Arg(("--limit",), help="Return a limited number of records") +ARG_LIMIT = Arg(("--limit",), type=positive_int(allow_zero=True), help="Return a limited number of records") job_states = tuple(state.value for state in JobState) ARG_JOB_STATE = Arg( ("--state",), diff --git a/airflow-core/tests/unit/cli/test_cli_parser.py b/airflow-core/tests/unit/cli/test_cli_parser.py index 97e0194202298..e136be55c5d81 100644 --- a/airflow-core/tests/unit/cli/test_cli_parser.py +++ b/airflow-core/tests/unit/cli/test_cli_parser.py @@ -635,6 +635,15 @@ def test_pools_set_and_delete_reject_output_flag(self, argv): assert e.value.code == 2 assert "unrecognized arguments: --output json" in stderr.getvalue() + @pytest.mark.parametrize("bad_value", ["abc", "-1"]) + def test_dags_list_jobs_rejects_invalid_limit(self, bad_value): + with contextlib.redirect_stderr(StringIO()) as stderr: + parser = cli_parser.get_parser() + with pytest.raises(SystemExit) as e: + parser.parse_args(["dags", "list-jobs", "--limit", bad_value]) + assert e.value.code == 2 + assert f"argument --limit: invalid positive int value: '{bad_value}'" in stderr.getvalue() + @pytest.mark.parametrize( "action_cmd", [