This is an automated email from the ASF dual-hosted git repository.
henry3260 pushed a commit to branch v3-3-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v3-3-test by this push:
new 240306e2492 [v3-3-test] Reject non-numeric --limit values in airflow
dags list-jobs (#72891) (#73214)
240306e2492 is described below
commit 240306e24922c4d4b9c1a3f58a5e2abddf9a3bdc
Author: Henry Chen <[email protected]>
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 <[email protected]>
Co-authored-by: Eason09053360
<[email protected]>
---
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",
[