Skip to content

Make deadline reads and serialization robust to dynamic/malformed intervals#68919

Open
seanghaeli wants to merge 3 commits into
apache:mainfrom
aws-mwaa:feature/deadline-response-serialization
Open

Make deadline reads and serialization robust to dynamic/malformed intervals#68919
seanghaeli wants to merge 3 commits into
apache:mainfrom
aws-mwaa:feature/deadline-response-serialization

Conversation

@seanghaeli

@seanghaeli seanghaeli commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

DeadlineAlert.interval is a JSON column (serialized timedelta or dynamic VariableInterval), but the /ui/dags/{dag_id}/deadlineAlerts response declared interval: float — any alert with a dict-shaped interval failed validation and the endpoint returned 500, breaking the run-page deadline badge.

Fix: interval becomes float | None with a validator (seconds for fixed intervals, None for dynamic), and interval is dropped from order_by (sorting a JSON column sorts by structure, not duration).

Robustness fixes from earlier revisions split out to #70421 per review.

Closes: #69245

@boring-cyborg boring-cyborg Bot added area:API Airflow's REST/HTTP API area:DAG-processing area:deadline-alerts AIP-86 (former AIP-57) labels Jun 23, 2026
@seanghaeli
seanghaeli force-pushed the feature/deadline-response-serialization branch from 12a8e11 to 352702c Compare June 23, 2026 21:30
@seanghaeli
seanghaeli marked this pull request as draft June 23, 2026 21:44
@seanghaeli
seanghaeli force-pushed the feature/deadline-response-serialization branch from 352702c to 31bd6d5 Compare June 23, 2026 22:11
@seanghaeli
seanghaeli marked this pull request as ready for review June 23, 2026 23:00
@potiuk potiuk added the ready for maintainer review Set after triaging when all criteria pass. label Jun 25, 2026

@pierrejeambrun pierrejeambrun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

I would make the code less verbose and keep only relevant comments/pieces. There are too many big comments some of them needs to be removed completely, some of them needs to be trimmed.

Overall looking good, just a few suggestions.

Another pair of eyes would be great on this.

Comment thread airflow-core/src/airflow/api_fastapi/core_api/datamodels/ui/deadline.py Outdated
Comment thread airflow-core/newsfragments/68919.bugfix.rst Outdated
@pierrejeambrun pierrejeambrun removed the ready for maintainer review Set after triaging when all criteria pass. label Jun 29, 2026
@pierrejeambrun pierrejeambrun added this to the Airflow 3.3.1 milestone Jun 29, 2026
@pierrejeambrun pierrejeambrun added the type:bug-fix Changelog: Bug Fixes label Jun 29, 2026
@seanghaeli
seanghaeli force-pushed the feature/deadline-response-serialization branch from 31bd6d5 to 1901333 Compare July 7, 2026 23:05
@seanghaeli
seanghaeli requested a review from henry3260 as a code owner July 7, 2026 23:05
@seanghaeli
seanghaeli force-pushed the feature/deadline-response-serialization branch from 6daac55 to 4a0ae29 Compare July 8, 2026 06:46
@potiuk potiuk added the ready for maintainer review Set after triaging when all criteria pass. label Jul 8, 2026

@pierrejeambrun pierrejeambrun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes doesn't seem related / necessary for fixing the related issue.

Can you keep the change as minimal as possible (for the issue we are trying to solve) and separate the rest in another extra PR.

Basically only those seems related:

M airflow-core/src/airflow/api_fastapi/core_api/datamodels/ui/deadline.py
M airflow-core/src/airflow/api_fastapi/core_api/openapi/_private_ui.yaml
M airflow-core/src/airflow/api_fastapi/core_api/routes/ui/deadlines.py
M airflow-core/tests/unit/api_fastapi/core_api/routes/ui/test_deadlines.py

Sean Ghaeli added 3 commits July 24, 2026 23:36
…ervals

Hardens the read and (de)serialization paths for deadline alerts so dynamic
(``VariableInterval``) and malformed stored data no longer break the UI/API.

- UI deadline-alert response: ``DeadlineAlert.interval`` is a JSON column holding
  the Airflow-serialized interval, not a plain number. Coerce it to seconds for a
  fixed ``timedelta`` and to ``None`` for a dynamic ``VariableInterval`` (resolved
  later by the scheduler), instead of letting Pydantic 500 on the dict. The
  ``interval`` field becomes ``float | None``.
- Drop ``interval`` from the sortable columns of the deadline-alerts endpoint:
  ordering by a JSON column sorts by structure/text, not duration, so the result
  was arbitrary and misleading.
- Deserialization: route by the encoder-stamped ``__class_path`` ahead of the
  ``reference_type`` name (a custom reference may share a class name with a
  builtin), and raise a clear error for a reference with no importable
  ``__class_path`` instead of an opaque ``KeyError``.
- ``Deadline.__repr__`` / ``DeadlineAlert.__repr__`` no longer raise: guard the
  ``dagrun`` relationship (the FK can be set while the relationship is None after a
  cascade delete) and handle the dict-shaped JSON interval. A ``__repr__`` must
  never raise.
- ``prune_deadlines`` explicitly excludes deadlines already marked ``missed`` so a
  missed deadline (whose callback is owned by the scheduler/triggerer) and its
  queued callback are never cascade-deleted.

Generated-by: Claude Code (Opus via Claude Code) on behalf of Sean Ghaeli
The sort-key comment restated a constraint already covered by
test_order_by_interval_is_rejected; the __class_path comment restated the
ValueError message right below it.

Generated-by: Claude Code (Opus)
Per review: keep only the interval coercion, order_by removal, and their
tests; move repr guards, decoder routing, and prune guard to a follow-up.
@seanghaeli

Copy link
Copy Markdown
Contributor Author

Hi @pierrejeambrun I've split up the PR so that this one just addresses #69245

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API area:DAG-processing area:deadline-alerts AIP-86 (former AIP-57) ready for maintainer review Set after triaging when all criteria pass. type:bug-fix Changelog: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PydanticSerializationError on deadline alerts UI endpoint for Dags overview and Dag run

3 participants