hkc-8010 commented on code in PR #70370:
URL: https://github.com/apache/airflow/pull/70370#discussion_r3976528012
##########
airflow-core/src/airflow/serialization/decoders.py:
##########
@@ -224,6 +225,35 @@ def decode_deadline_alert(encoded_data: dict):
)
+def decode_deadline_alert_model(deadline_alert: DeadlineAlertModel) ->
SerializedDeadlineAlert:
+ """
+ Decode a ``DeadlineAlert`` ORM row into its serialized representation.
+
+ :meta private:
+ """
+ return decode_deadline_alert(
+ {
+ DeadlineAlertFields.REFERENCE: deadline_alert.reference,
+ DeadlineAlertFields.INTERVAL: deadline_alert.interval,
+ DeadlineAlertFields.CALLBACK: deadline_alert.callback_def,
+ }
+ )
+
+
+def resolve_deadline_alert_interval(alert: SerializedDeadlineAlert) ->
datetime.timedelta:
+ """
+ Resolve a decoded alert's interval to a ``timedelta``.
+
+ A ``VariableInterval`` reads its Airflow Variable here, so this is only
called at the point
+ a deadline is actually calculated.
+
+ :meta private:
+ """
+ if isinstance(alert.interval, VariableInterval):
+ return alert.interval.resolve()
Review Comment:
Done. The decode and the resolve are now wrapped in `try/except (ValueError,
TypeError)` inside `_recalculate_dagrun_queued_at_deadlines`, which logs a
warning naming the deadline and the dag run and moves on to the next one, so a
missing or non-integer Variable leaves that deadline at its old time instead of
failing the clear. `decode_deadline_alert` can also raise `TypeError` on an
unknown interval type, so that is caught in the same place. Kept it at the call
site rather than in the helper like you suggested, so DagRun creation still
raises. New test for it:
`test_clear_task_instances_skips_deadline_with_unresolvable_interval`.
##########
airflow-core/src/airflow/serialization/decoders.py:
##########
@@ -24,6 +24,7 @@
import dateutil.relativedelta
from airflow._shared.module_loading import import_string
+from airflow.sdk.definitions.deadline import VariableInterval
Review Comment:
Gone now. #71802 merged since you wrote this, so
`resolve_deadline_alert_interval()` isinstance-checks the core
`SerializedVariableInterval` and the module-level SDK import is removed.
`decode_deadline_alert` keeps its own function-local `VariableInterval` import
exactly as it is on `main`. After the rebase this PR adds no `airflow.sdk`
import to core anywhere, and `generated/known_sdk_imports_in_core.txt` is no
longer part of the diff.
--
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]