pierrejeambrun commented on code in PR #68919:
URL: https://github.com/apache/airflow/pull/68919#discussion_r3492654625
##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/ui/deadline.py:
##########
@@ -52,9 +53,42 @@ class DeadlineAlertResponse(BaseModel):
id: UUID
name: str | None = None
reference_type: str = Field(validation_alias=AliasPath("reference",
"reference_type"))
- interval: float = Field(description="Interval in seconds between deadline
evaluations.")
+ interval: float | None = Field(
+ default=None,
+ description=(
+ "Interval in seconds between the reference time and the deadline. "
+ "Null for a dynamic interval (e.g. a VariableInterval) whose value
is "
+ "only resolved at scheduler evaluation time."
+ ),
+ )
created_at: datetime
+ @field_validator("interval", mode="before")
+ @classmethod
+ def coerce_interval_to_seconds(cls, value: Any) -> float | None:
+ """
+ Coerce the stored ``interval`` into seconds.
+
+ ``DeadlineAlert.interval`` is a JSON column holding the
Airflow-serialized form
+ of the SDK interval, not a plain number. A fixed ``timedelta``
serializes to
+ ``{"__classname__": "datetime.timedelta", "__data__": <seconds>}`` and
a dynamic
+ ``VariableInterval`` to ``{"__classname__": ".../VariableInterval",
"__data__": {...}}``.
+ Without this coercion Pydantic cannot turn that dict into ``float``
and the
+ ``/ui/dags/{dag_id}/deadlineAlerts`` endpoint raises a 500, which
breaks the
+ run-page deadline status badge. Return the seconds for a fixed
interval, or
+ ``None`` for a dynamic one (resolved later by the scheduler).
Review Comment:
```suggestion
Without this coercion Pydantic cannot turn that dict into ``float``
and the
``/ui/dags/{dag_id}/deadlineAlerts`` endpoint raises a 500. Return
the seconds for a fixed interval, or
``None`` for a dynamic one (resolved later by the scheduler).
```
##########
airflow-core/newsfragments/68919.bugfix.rst:
##########
@@ -0,0 +1 @@
+Fixed the deadline UI/API endpoints raising ``500`` errors on deadline alerts
whose interval is stored as a serialized object rather than a plain number.
``DeadlineAlert.interval`` is a JSON column holding the Airflow-serialized
interval (a fixed ``timedelta`` or a dynamic ``VariableInterval``); the
``/ui/dags/{dag_id}/deadlineAlerts`` response now coerces it to seconds for a
fixed interval and to ``null`` for a dynamic one instead of failing to
validate. Sorting deadline alerts by ``interval`` (which would sort by JSON
structure, not duration) is no longer offered. Deserializing a corrupt or
unrecognized deadline reference now raises a clear error instead of an opaque
``KeyError``, custom references that share a class name with a builtin are
routed correctly via ``__class_path``, and ``Deadline.__repr__`` no longer
raises when the ``dagrun`` relationship has been severed. ``prune_deadlines``
now explicitly skips deadlines already marked ``missed`` so their queued
callbacks are neve
r cascade-deleted.
Review Comment:
To remove.
--
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]