henry3260 commented on code in PR #70249:
URL: https://github.com/apache/airflow/pull/70249#discussion_r3650254959
##########
airflow-ctl/src/airflowctl/ctl/cli_config.py:
##########
@@ -566,7 +576,7 @@ def _python_type_from_string(type_name: str | type) -> type
| Callable:
"dict": json_dict_type,
"tuple": tuple,
"set": set,
- "datetime.datetime": datetime.datetime,
+ "datetime.datetime": iso_datetime_type,
Review Comment:
Could we add a test like this?
```
def test_command_factory_wires_iso_parser_to_datetime_params(self):
"""A generated datetime CLI arg parses an ISO date end to end."""
command_factory = CommandFactory()
dagrun_list_args = []
for group in command_factory.group_commands:
if group.name != "dagrun":
continue
for sub in group.subcommands:
if sub.name == "list":
dagrun_list_args = list(sub.args)
break
start_date_arg = next(a for a in dagrun_list_args if a.flags ==
("--start-date",))
assert start_date_arg.kwargs["type"]("2026-07-01") ==
datetime.datetime(2026, 7, 1)
```
##########
airflow-ctl/tests/airflow_ctl/ctl/test_cli_config.py:
##########
@@ -364,6 +365,37 @@ def test_json_dict_type_rejects_non_object_json(self,
value):
with pytest.raises(argparse.ArgumentTypeError, match="expected JSON
object"):
json_dict_type(value)
+ def test_iso_datetime_type_returns_datetime_input_unchanged(self):
+ """A datetime.datetime input is returned as-is without re-parsing."""
+ import datetime
+
+ value = datetime.datetime(2026, 7, 1, tzinfo=datetime.timezone.utc)
+
+ assert iso_datetime_type(value) is value
+
+ @pytest.mark.parametrize(
+ ("value", "expected"),
+ [
+ ("2026-07-01", "2026-07-01T00:00:00"),
+ ("2026-07-01T00:00:00", "2026-07-01T00:00:00"),
+ ("2026-07-01T12:34:56+00:00", "2026-07-01T12:34:56+00:00"),
+ ],
+ )
+ def test_iso_datetime_type_parses_iso_string(self, value, expected):
+ """An ISO-8601 datetime string (date-only or full) is parsed into a
datetime.
+
+ Regression test for https://github.com/apache/airflow/issues/70232:
previously the
+ bare ``datetime.datetime`` class was used as the argparse ``type=``
callable, so
+ argparse called ``datetime.datetime(value)`` on the raw string, which
always raised
+ a ``TypeError`` regardless of the input.
+ """
Review Comment:
```suggestion
"""An ISO-8601 datetime string (date-only or full) is parsed into a
datetime."""
```
--
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]