SameerMesiah97 opened a new pull request, #64751:
URL: https://github.com/apache/airflow/pull/64751

   **Description**
   
   This change adds support for **dynamic interval resolution** in 
`encode_deadline_alert` by allowing interval objects that implement a 
`.resolve()` method (e.g. `VariableInterval`) to be evaluated during 
serialization. The encoder now detects and invokes `.resolve()` when present, 
converting the result into a `timedelta` for serialization while preserving 
existing behavior for `timedelta` intervals.
   
   The encoder is also made **idempotent**, returning early when given an 
already-serialized dict to prevent double-encoding during DAG re-serialization. 
Additionally, a `VariableInterval` class is introduced under 
`airflow.sdk.definitions.deadline`, enabling intervals to be sourced from 
Airflow Variables (interpreted as minutes).
   
   **Rationale**
   
   `DeadlineAlert `intervals are part of DAG configuration and are resolved at 
**DAG parse / serialization time**, not at runtime. Supporting runtime 
resolution would require introducing a separate execution-time mechanism for 
interval evaluation, diverging from how `timedelta` intervals are handled today 
and increasing system complexity for a relatively small, opt-in feature.
   
   This change instead resolves intervals at **serialization time**, which is 
the last point before the value is persisted to the database. This ensures that 
both static (`timedelta`) and dynamic (`VariableInterval`) intervals are 
materialized in a single, consistent phase without introducing any changes to 
scheduler or runtime behavior. As a result, interval values remain stable for 
the lifetime of a DagRun while keeping the implementation minimal and aligned 
with existing architecture.
   
   **Tests**
   
   Added unit tests verifying that:
   
   * `timedelta` intervals are correctly serialized.
   * `.resolve()` is invoked for dynamic interval objects.
   * encoding is idempotent (`encode(x) == encode(encode(x))`).
   * callback fields are preserved during encoding.
   * `VariableInterval.resolve()` correctly converts a Variable value (in 
minutes) to a `timedelta` (mocked via `Variable.get`).
   
   **Documentation**
   
   * Modified 'how-to' docs to mention that `DeadlineAlert `intervals may be 
dynamically resolved via VariableInterval.
   * Added docstring for `VariableInterval` with usage example and behavior 
notes.
   
   **Backwards Compatibility**
   
   This change is fully backwards compatible. Existing `timedelta`-based 
intervals continue to behave as before, and dynamic interval resolution is 
strictly opt-in via objects implementing `.resolve()` (e.g. `VariableInterval`).
   
   Closes: #63852


-- 
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]

Reply via email to