This is an automated email from the ASF dual-hosted git repository.

henry3260 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 022ff83f145 Reject non-numeric --limit values in airflow dags 
list-jobs (#72891)
022ff83f145 is described below

commit 022ff83f14563cde9b91e87cd5a18253997384e3
Author: Y-C <[email protected]>
AuthorDate: Wed Sep 16 01:26:43 2026 +0800

    Reject non-numeric --limit values in airflow dags list-jobs (#72891)
    
    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.
    
    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 241aa602a68..234a812ba8d 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 97e01942022..e136be55c5d 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 @@ class TestCli:
         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",
         [

Reply via email to