airflowctl: fix datetime.datetime CLI parameters rejecting all input#70249
Open
bramhanandlingala wants to merge 2 commits into
Open
airflowctl: fix datetime.datetime CLI parameters rejecting all input#70249bramhanandlingala wants to merge 2 commits into
bramhanandlingala wants to merge 2 commits into
Conversation
bramhanandlingala
requested review from
bugraoz93,
dheerajturaga,
henry3260 and
potiuk
as code owners
July 22, 2026 16:26
Contributor
Author
|
@ bugraoz93, @dheerajturaga, @henry3260 and @potiuk @kaxil |
Contributor
Author
|
@ bugraoz93, @dheerajturaga, @henry3260 and @potiuk @kaxil @Lee-W @shahar1 Did I miss anyone in the list, please advise |
henry3260
reviewed
Jul 25, 2026
Comment on lines
+385
to
+391
| """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. | ||
| """ |
Contributor
There was a problem hiding this comment.
Suggested change
| """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, |
Contributor
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.