Skip to content

airflowctl: fix datetime.datetime CLI parameters rejecting all input#70249

Open
bramhanandlingala wants to merge 2 commits into
apache:mainfrom
bramhanandlingala:fix/#70232
Open

airflowctl: fix datetime.datetime CLI parameters rejecting all input#70249
bramhanandlingala wants to merge 2 commits into
apache:mainfrom
bramhanandlingala:fix/#70232

Conversation

@bramhanandlingala

Copy link
Copy Markdown
Contributor

closes: #70232

What

datetime.datetime-typed CLI parameters in airflowctl (e.g.
dagrun list --start-date/--end-date) rejected every input value.

Root cause

_python_type_from_string() in cli_config.py mapped
datetime.datetime to the bare class as the argparse type=
callable. argparse calls type(value) on the raw CLI string, so it
tried datetime.datetime("2026-07-01") — but that constructor expects
positional (year, month, day, ...) ints, not a string, so it always
raised TypeError, regardless of the input format.

Fix

Added iso_datetime_type(), a real parser using
datetime.datetime.fromisoformat(), and mapped datetime.datetime to
it instead of the bare class. This mirrors the existing fix already
applied for dictjson_dict_type.

@bramhanandlingala

Copy link
Copy Markdown
Contributor Author

@ bugraoz93, @dheerajturaga, @henry3260 and @potiuk @kaxil
request you please review and approve for merge this fix

@bramhanandlingala

bramhanandlingala commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

@ bugraoz93, @dheerajturaga, @henry3260 and @potiuk @kaxil @Lee-W @shahar1

Did I miss anyone in the list, please advise
after a while this code fix would be stale , trying to get approval as soon as possible, any approvals or guidance is motivation to improve my work, please help

@henry3260 henry3260 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

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.
"""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@shahar1 shahar1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

airflowctl: datetime.datetime-typed CLI parameters don't accept any value

3 participants