You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ra...@apache.org on 2026/09/21 15:01:15 UTC
(airflow) 05/15: [v3-3-test] Reject non-numeric --limit values in airflow dags list-jobs (#72891) (#73214)
This is an automated email from the ASF dual-hosted git repository.
vatsrahul1001 pushed a commit to branch v3-3-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
commit c4f9ba5057ea9dafdf3754c36acb47a60ea88a22
Author: Henry Chen <he...@apache.org>
AuthorDate: Wed Sep 16 03:45:12 2026 +0800
[v3-3-test] Reject non-numeric --limit values in airflow dags list-jobs (#72891) (#73214)
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.
(cherry picked from commit 022ff83f14563cde9b91e87cd5a18253997384e3)
Co-authored-by: Y-C <ea...@gmail.com>
Co-authored-by: Eason09053360 <18...@users.noreply.github.com>
---
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 c8a5e224e90..8f1386fccef 100644
--- a/airflow-core/src/airflow/cli/cli_config.py
+++ b/airflow-core/src/airflow/cli/cli_config.py
@@ -294,7 +294,7 @@ ARG_DR_STATE = Arg(
# 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 2a0680f08ef..d9a8080ed18 100644
--- a/airflow-core/tests/unit/cli/test_cli_parser.py
+++ b/airflow-core/tests/unit/cli/test_cli_parser.py
@@ -608,6 +608,15 @@ class TestCli:
"airflow db export-archived command error: argument --export-format: invalid choice" in error_msg
)
+ @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",
[