From 896e51426eba70fe0bb96be5ac27103c6b1abb5e Mon Sep 17 00:00:00 2001 From: Dev-iL <6509619+Dev-iL@users.noreply.github.com> Date: Sat, 14 Mar 2026 11:20:08 +0200 Subject: [PATCH] Fix airflowctl boolean flags on Python 3.14 --- airflow-ctl/src/airflowctl/ctl/cli_config.py | 5 ++++- .../tests/airflow_ctl/ctl/test_cli_config.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/airflow-ctl/src/airflowctl/ctl/cli_config.py b/airflow-ctl/src/airflowctl/ctl/cli_config.py index bdcd8b2fb9060..5f17c60335734 100755 --- a/airflow-ctl/src/airflowctl/ctl/cli_config.py +++ b/airflow-ctl/src/airflowctl/ctl/cli_config.py @@ -152,7 +152,10 @@ def type(x): return self._is_valid_directory(parser, x) self.kwargs["type"] = type - parser.add_argument(*self.flags, **self.kwargs) + kwargs = self.kwargs.copy() + if kwargs.get("action") is argparse.BooleanOptionalAction: + kwargs.pop("type", None) + parser.add_argument(*self.flags, **kwargs) def _is_valid_directory(self, parser, arg): if not os.path.isdir(arg): diff --git a/airflow-ctl/tests/airflow_ctl/ctl/test_cli_config.py b/airflow-ctl/tests/airflow_ctl/ctl/test_cli_config.py index 6d5bf39e7ab61..117f874c34651 100644 --- a/airflow-ctl/tests/airflow_ctl/ctl/test_cli_config.py +++ b/airflow-ctl/tests/airflow_ctl/ctl/test_cli_config.py @@ -17,6 +17,7 @@ from __future__ import annotations +import argparse from argparse import BooleanOptionalAction from textwrap import dedent @@ -288,6 +289,22 @@ def delete(self, backfill_id: str) -> ServerResponseError | None: class TestCliConfigMethods: + def test_add_to_parser_drops_type_for_boolean_optional_action(self): + """Test add_to_parser removes type for BooleanOptionalAction.""" + parser = argparse.ArgumentParser() + arg = Arg( + flags=("--run-backwards",), + action=BooleanOptionalAction, + default=False, + help="run_backwards for backfill operation", + type=bool, + ) + + arg.add_to_parser(parser) + + assert parser.parse_args(["--run-backwards"]).run_backwards is True + assert parser.parse_args(["--no-run-backwards"]).run_backwards is False + def test_merge_commands(self, no_op_method): """Test the merge_commands method.""" # Create two Command objects with different names and help texts