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

Nobody has claimed this yet.

Assessment

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

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.

Description

area:core kind:bug
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.

Dominant language
Python
Stars
46.9k
Forks
17.9k
Avg merge
2d 5h
Merged PRs (30d)
480

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/airflow

All issues in apache/airflow

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.