hkc-8010 opened a new pull request, #70370:
URL: https://github.com/apache/airflow/pull/70370
## Summary
Clearing a DAG run or task instance whose DAG defines a deadline referencing
the run's queued-at time (`DeadlineReference.DAGRUN_QUEUED_AT`) raised
`TypeError: unsupported type for timedelta seconds component: dict` and
surfaced as an HTTP 500 in the API server.
Since 3.3.0 the `deadline_alert.interval` column is JSON (migration
`0117_3_3_0_change_deadline_interval_to_json.py`, from #64751), holding a
serialized `timedelta` or `VariableInterval`, e.g. `{"__classname__":
"datetime.timedelta", "__version__": 2, "__data__": 3600.0}`.
`_recalculate_dagrun_queued_at_deadlines` (called from `clear_task_instances`)
still passed that raw dict into `timedelta(seconds=...)`. Every other consumer
(DagRun creation in `serialization/definitions/dag.py`, the model `__repr__`)
decodes the JSON first; only the clear path was missed.
The fix decodes the interval the same way DagRun creation does, via
`decode_deadline_alert`, then resolves a `VariableInterval` to a `timedelta`
before recalculating.
## Changes
- `airflow-core/src/airflow/models/taskinstance.py`: decode the JSON
interval via `decode_deadline_alert` and resolve `VariableInterval` in
`_recalculate_dagrun_queued_at_deadlines`.
- `airflow-core/tests/unit/models/test_taskinstance.py`: the existing test
stored the interval as a plain float, so it never exercised the JSON path. It
now stores the serialized envelope and is parametrized over a fixed `timedelta`
and a `VariableInterval`. Both cases fail on `main` with the reported
`TypeError` and pass with the fix.
closes: #70368
## PR Checklist
- [x] Targeted at the `main` branch
- [x] Tests added (fixed-interval and VariableInterval cases, both reproduce
the bug on `main`)
- [x] `prek` hooks pass on the changed files (ruff, ruff-format, mypy for
airflow-core)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]