airflowctl: datetime.datetime-typed CLI parameters don't accept any value
- Dominant language
- Python
- Stars
- 46.9k
- Forks
- 17.8k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 472
Description
### Under which category would you file this issue?
Airflow Core
### Apache Airflow version
airflow 3.2.2 / airflow-ctl 0.1.5 (also present on `main`)
### What happened and how to reproduce it?
`airflowctl dagrun list` (and any other auto-generated CLI command with a `datetime.datetime`-typed parameter, e.g. `--start-date`/`--end-date`) rejects every possible input string. No date format — plain date, full ISO-8601, anything — will parse.
**Reproduction:**
```bash
airflowctl dagrun list -e --start-date "2026-07-01" --limit 1
# argument --start-date: invalid datetime value: '2026-07-01'
airflowctl dagrun list -e --start-date "2026-07-01T00:00:00" --limit 1
# argument --start-date: invalid datetime value: '2026-07-01T00:00:00'
```
**Root cause:**
In `airflow-ctl/src/airflowctl/ctl/cli_config.py`, `_python_type_from_string` builds the argparse `type=` callable for CLI arguments straight from the OpenAPI-derived operation signatures:
```python
mapping: dict[str, type | Callable] = {
"int": int,
"float": float,
"bool": bool,
"str": str,
"bytes": bytes,
"list": list,
"dict": json_dict_type,
"tuple": tuple,
"set": set,
"datetime.datetime": datetime.datetime,
"dict[str, typing.Any]": json_dict_type,
}
```
For any parameter annotated `datetime.datetime`, this passes the bare `datetime.datetime` class to argparse as `type=`. argparse then calls `type(value)` on
the raw CLI string, i.e. `datetime.datetime("2026-07-01")` — invoetime.datetime(year, month, day, ...)`), not a parser. Since theconstructor expects positional ints, passing a single string always raises a `TypeError`, which argparse reports as `invalid datetime value: '...'` regardless
of the input.
Notably, the exact same class of bug existed for `dict`-typed parxed by mapping to `json_dict_type` (a real parser using`json.loads`) instead of the bare `dict` constructor. The `datetime.datetime` entry was missed and still uses the bare type.
### What you think should happen instead?
`datetime.datetime` should map to an actual parsing function, not the bare class, e.g.:
```python
def iso_datetime_type(val: str) -> datetime.datetime:
"""Parse an ISO-8601 datetime string."""
try:
return datetime.datetime.fromisoformat(val)
except ValueError as e:
raise argparse.ArgumentTypeError(f"invalid datetime value: {val!r}") from e
```
and:
```python
"datetime.datetime": iso_datetime_type,
```
This mirrors the existing fix pattern already used for `dict` → `e mapping.
### Operating System
macOS (also confirmed against a production Airflow instance, running Linux / Debian distroless)
### Deployment
Other
### Apache Airflow Provider(s)
_No response_
### Versions of Apache Airflow Providers
Installed via `uv tool install apache-airflow-ctl`. This bug report is explicitly about the airflowctl tool.
### Official Helm Chart version
Not Applicable
### Kubernetes Version
Not Applicable
### Helm Chart configuration
Not Applicable
### Docker Image customizations
Not Applicable
### Anything else?
Confirmed present at:
- Tag `airflow-ctl/0.1.5` (commit `30e72a3`) — `airflow-ctl/src/airflowctl/ctl/cli_config.py:517`
- `main` (as of 2026-07-22) — same file, `cli_config.py:549`, unchanged
Affects every argparse-generated CLI command whose underlying operation signature has a `datetime.datetime`-typed parameter (e.g. `dagrun list --start-date/--end-date`), not just this one command.
### Are you willing to submit PR?
- [ ] Yes I am willing to submit a PR!
### Code of Conduct
- [x] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
Contributor guide
Research direction
Start in airflow-ctl/src/airflowctl/ctl/cli_config.py at _python_type_from_string and reproduce the airflowctl dagrun list --start-date example. Compare the datetime.datetime mapping with the existing json_dict_type parser pattern. Done means valid ISO-8601 datetime arguments work for generated CLI commands and invalid values produce a clear argparse error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100