airflowctl: fix datetime.datetime CLI parameters rejecting all input - #70249
airflowctl: fix datetime.datetime CLI parameters rejecting all input#70249bramhanandlingala wants to merge 3 commits into
Conversation
|
@ bugraoz93, @dheerajturaga, @henry3260 and @potiuk @kaxil |
|
@ bugraoz93, @dheerajturaga, @henry3260 and @potiuk @kaxil @Lee-W @shahar1 Did I miss anyone in the list, please advise |
| """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. | ||
| """ |
There was a problem hiding this comment.
| """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. | |
| """ | |
| """An ISO-8601 datetime string (date-only or full) is parsed into a datetime.""" |
| "tuple": tuple, | ||
| "set": set, | ||
| "datetime.datetime": datetime.datetime, | ||
| "datetime.datetime": iso_datetime_type, |
There was a problem hiding this 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)
93e7f65 to
24e9f97
Compare
|
Hi @henry3260 Thanks for the detailed review and the helpful suggestion! I've updated the PR by simplifying the docstring and adding the end-to-end regression test to verify that CommandFactory wires iso_datetime_type for datetime CLI parameters. I'd appreciate it if you could take another look when you have a chance. |
closes: #70232
What
datetime.datetime-typed CLI parameters inairflowctl(e.g.dagrun list --start-date/--end-date) rejected every input value.Root cause
_python_type_from_string()incli_config.pymappeddatetime.datetimeto the bare class as the argparsetype=callable. argparse calls
type(value)on the raw CLI string, so ittried
datetime.datetime("2026-07-01")— but that constructor expectspositional
(year, month, day, ...)ints, not a string, so it alwaysraised
TypeError, regardless of the input format.Fix
Added
iso_datetime_type(), a real parser usingdatetime.datetime.fromisoformat(), and mappeddatetime.datetimetoit instead of the bare class. This mirrors the existing fix already
applied for
dict→json_dict_type.Gen-AI disclosure: I used a generative AI tool to help identify the root
cause, write tests, and draft the PR description. I reviewed, tested, and
verified all changes locally before submitting.
Was generative AI tooling used to co-author this PR?
Generated-by: Claude following the guidelines