apache / apache/airflow

Clearing a DAG run/task instance with a DagRunQueuedAtDeadline fails with TypeError: unsupported type for timedelta seconds component: dict

Open Beginner friendly
#70,368 1 comment 0 reactions 0 assignees View on GitHub
area:core kind:bug
Dominant language
Python
Stars
46.9k
Forks
17.8k
Avg merge
2d 9h
Merged PRs (30d)
472

Description

### Apache Airflow version

3.3.0 and later

### What happened

Clearing a failed DAG run or task instance returns HTTP 500 ("Internal Service Error") in the UI when the DAG defines a deadline that references the DAG run's `queued_at` time (`DeadlineReference.DAGRUN_QUEUED_AT`). The API server logs:

```
TypeError: unsupported type for timedelta seconds component: dict
```

### What you think should happen instead

The clear should succeed, and the queued-at deadline should be recalculated against the new `queued_at`.

### Root cause

In 3.3.0, migration `0117_3_3_0_change_deadline_interval_to_json.py` (from #64751, which added `VariableInterval` support) changed the `deadline_alert.interval` column from FLOAT to JSON. Existing values were rewritten into the serde envelope, e.g. `{"__classname__": "datetime.timedelta", "__version__": 2, "__data__": 3600.0}`.

`_recalculate_dagrun_queued_at_deadlines()` in `airflow-core/src/airflow/models/taskinstance.py` (called from `clear_task_instances`) still reads the raw column and does `timedelta(seconds=deadline_alert.interval)`, passing the JSON dict straight into `timedelta`. Every other consumer (DagRun creation in `serialization/definitions/dag.py`, the model `__repr__`) decodes the JSON first. Only the clear path was missed.

### How to reproduce

1. Define a DAG with a deadline referencing `DeadlineReference.DAGRUN_QUEUED_AT`.
2. Let a run queue so a `Deadline` row is created.
3. Clear the DAG run or one of its task instances.

The API server returns 500 with the `TypeError` above.

### Workarounds

- Delete the task instance in the UI instead of clearing it.
- Temporarily remove the `deadline` parameter from the DAG.

### Are you willing to submit a PR?

Yes.

Contributor guide

Open the contributing guide

Research direction

Start in airflow-core/src/airflow/models/taskinstance.py at _recalculate_dagrun_queued_at_deadlines(), called by clear_task_instances, and compare its interval handling with DagRun creation in serialization/definitions/dag.py and the model __repr__. Verify the clear path handles the migrated deadline interval correctly; done means clearing a DAG run or task instance succeeds and recalculates the queued-at deadline without the TypeError.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.