ferruzzi commented on code in PR #64751:
URL: https://github.com/apache/airflow/pull/64751#discussion_r3761122255
##########
airflow-core/src/airflow/models/deadline_alert.py:
##########
@@ -50,13 +50,22 @@ class DeadlineAlert(Base):
name: Mapped[str | None] = mapped_column(String(250), nullable=True)
description: Mapped[str | None] = mapped_column(Text, nullable=True)
reference: Mapped[dict] = mapped_column(JSON, nullable=False)
- interval: Mapped[float] = mapped_column(Float, nullable=False)
+ interval: Mapped[dict] = mapped_column(JSON, nullable=False)
callback_def: Mapped[dict] = mapped_column(JSON, nullable=False)
def __repr__(self):
- interval_seconds = int(self.interval)
- if interval_seconds >= 3600:
+ interval_seconds = None
+
+ if isinstance(self.interval, (int, float)):
+ interval_seconds = int(self.interval)
+
+ elif isinstance(self.interval, datetime.timedelta):
+ interval_seconds = int(self.interval.total_seconds())
+
+ if interval_seconds is None:
+ interval_display = "dynamic"
+ elif interval_seconds >= 3600:
Review Comment:
This is a regression, changing `interval` from `float` to `dict/JSON` means
that not only can the first isinstance not possibly catch, it will raise an
exception since you meant to use `datetime.timedelta` but instead you are using
`datetime.datetime.timedelta`
`test_deadline_alert_repr` misses it because `DEADLINE_INTERVAL = 60`
short-circuits on the first branch.
untested claude cuggestion:
```python
def __repr__(self):
from airflow.sdk.definitions.deadline import VariableInterval
from airflow.sdk.serde import deserialize
interval = self.interval
if isinstance(interval, dict):
try:
interval = deserialize(interval)
except Exception: # noqa: BLE001 - a repr must never raise
interval = None
interval_seconds = None
interval_display = "unknown"
if isinstance(interval, VariableInterval):
interval_display = f"var:{interval.key}"
elif isinstance(interval, timedelta):
interval_seconds = int(interval.total_seconds())
elif isinstance(interval, (int, float)):
# Bare seconds predate 3.3.0; migration 0117 should have
converted these.
interval_seconds = int(interval)
if interval_seconds is not None:
if abs(interval_seconds) >= 3600:
interval_display = f"{interval_seconds // 3600}h"
elif abs(interval_seconds) >= 60:
interval_display = f"{interval_seconds // 60}m"
else:
interval_display = f"{interval_seconds}s"
return (
f"[DeadlineAlert] "
f"id={str(self.id)[:8]}, "
f"created_at={self.created_at}, "
f"name={self.name or 'Unnamed'}, "
f"reference={self.reference}, "
f"interval={interval_display}, "
f"callback={self.callback_def}"
)
```
--
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]