ashb commented on code in PR #67947:
URL: https://github.com/apache/airflow/pull/67947#discussion_r3558553258
##########
airflow-ctl/tests/airflow_ctl/ctl/test_cli_config.py:
##########
@@ -321,6 +321,41 @@ def list(self, is_alive: bool | None = None) ->
JobCollectionResponse | ServerRe
assert is_alive_arg.kwargs["default"] is None
assert is_alive_arg.kwargs["type"] is bool
+ def test_command_factory_body_bool_field_defaults_to_none(self, tmp_path):
+ """Bool fields expanded from a Pydantic body must default to None, not
False.
+
+ Otherwise the dispatcher's ``is not None`` filter passes an unset flag
+ through as ``False``, silently overriding API-side defaults that are
+ ``True`` (e.g. ``ClearTaskInstancesBody.only_failed``).
+ """
+ temp_file = self._save_temp_operations_py(
+ tmp_path=tmp_path,
+ file_content="""
+ class TasksOperations(BaseOperations):
+ def clear(self, dag_id: str, body: ClearTaskInstancesBody):
+ self.response = self.client.post(
+ f"dags/{dag_id}/clearTaskInstances",
+ json=body.model_dump(mode="json"),
+ )
+ return self.response
+ """,
+ )
+
+ command_factory = CommandFactory(file_path=str(temp_file))
+ clear_args: list = []
+ for generated_group_command in command_factory.group_commands:
+ if generated_group_command.name != "tasks":
+ continue
+ for sub_command in generated_group_command.subcommands:
+ if sub_command.name == "clear":
+ clear_args = list(sub_command.args)
+ break
+
+ for flag in ("--dry-run", "--only-failed", "--reset-dag-runs",
"--run-on-latest-version"):
+ arg = next(a for a in clear_args if a.flags == (flag,))
+ assert arg.kwargs["action"] == BooleanOptionalAction, flag
+ assert arg.kwargs["default"] is None, flag
Review Comment:
Tri-sate bools are a huge code smell. From a quick look, all of these values
should be True or False, none of them make sense as "None/unset".
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]