shivaam commented on code in PR #64751:
URL: https://github.com/apache/airflow/pull/64751#discussion_r3114762335
##########
task-sdk/src/airflow/sdk/definitions/deadline.py:
##########
@@ -340,3 +343,58 @@ def decorator(
return reference_class
return decorator
+
+
[email protected](frozen=True)
+class VariableInterval:
+ """
+ Interval backed by an Airflow Variable.
+
+ This allows DeadlineAlert intervals to be configured dynamically using
+ Airflow Variables. The variable value is interpreted as minutes and
+ converted into a ``timedelta``.
+
+ ------
+ Usage:
+ ------
+
+ .. code-block:: python
+
+ from airflow.sdk import DAG, DeadlineAlert, DeadlineReference,
AsyncCallback
+
+ DAG(
+ dag_id="dag_with_variable_interval",
+ deadline=DeadlineAlert(
+ reference=DeadlineReference.DAGRUN_QUEUED_AT,
+ interval=VariableInterval("deadline_minutes"),
+ callback=AsyncCallback(my_callback),
+ ),
+ )
+
+ ------
+ Notes:
+ ------
+ * Resolution occurs when deadlines are evaluated (during DagRun creation).
+ * Changes to the Variable affect only newly parsed DAGs and future DagRuns.
+ * Existing deadlines are not retroactively updated.
+ """
+
+ key: str
+
+ def resolve(self) -> timedelta:
+ try:
+ value = Variable.get(self.key)
+ except KeyError as e:
+ raise ValueError(f"VariableInterval '{self.key}' not found") from e
+
Review Comment:
`Variable.get()` raises `AirflowRuntimeError` when a key is missing, not
`KeyError` (see `variable.py:47-58`). Since no `default` is passed here, the
`AirflowRuntimeError` re-raises and this `except KeyError` block never
triggers. The test passes because it mocks `Variable.get` with
`side_effect=KeyError("missing")`.
Should be:
```python
from airflow.sdk.exceptions import AirflowRuntimeError
try:
value = Variable.get(self.key)
except AirflowRuntimeError as e:
raise ValueError(f"VariableInterval '{self.key}\ not found") from e
```
--
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]