apache / apache/airflow

`datetime.timedelta` serde cannot deserialize integer payloads, crashing scheduler during DeadlineAlert DAG-run creation

Open Beginner friendly
#72,319 1 comment 0 reactions 0 assignees View on GitHub
kind:bug needs-triage
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?

Task SDK

### Apache Airflow version

3.3.0

### What happened and how to reproduce it?

The scheduler crashes while creating an asset-triggered DAG run for a DAG with a `DeadlineAlert` interval of `timedelta(minutes=45)`.

The serialized DAG payload observed in the scheduler traceback contains:

```python
{
"__classname__": "datetime.timedelta",
"__version__": 2,
"__data__": 2700,
}
```

The SDK datetime deserializer only accepts `str | float` for `datetime.timedelta`:

```python
if cls is datetime.timedelta and isinstance(data, str | float):
return datetime.timedelta(seconds=float(data))
```

Since `2700` is an `int`, deserialization raises:

```text
TypeError: unknown date/time format datetime.timedelta
```

The exception is unhandled in scheduler DAG-run creation and terminates the scheduler process.

### Minimal reproduction

```python
from datetime import timedelta

from airflow.sdk.serde import CLASSNAME, DATA, VERSION, deserialize

serialized_timedelta = {
CLASSNAME: "datetime.timedelta",
VERSION: 2,
DATA: 2700,
}

assert deserialize(serialized_timedelta) == timedelta(minutes=45)
```

### Actual result

```text
TypeError: unknown date/time format datetime.timedelta
```

### Expected result

```python
timedelta(minutes=45)
```

### Proposed fix

Accept integer second values alongside the already accepted string and float forms.

### What you think should happen instead?

_No response_

### Operating System

_No response_

### Deployment

None

### Apache Airflow Provider(s)

_No response_

### Versions of Apache Airflow Providers

_No response_

### Official Helm Chart version

Not Applicable

### Kubernetes Version

_No response_

### Helm Chart configuration

_No response_

### Docker Image customizations

_No response_

### Anything else?

_No response_

### 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

Open the contributing guide

Research direction

Start at the datetime.timedelta branch in airflow.sdk.serde.deserialize and run the minimal reproduction from the issue. Done means the integer payload 2700 deserializes to timedelta(minutes=45) without the unknown date/time format error, while the existing string and float forms continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, data-engineering
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.