Skip to content

Add Jinja template rendering for deadline callback kwargs#68408

Draft
seanghaeli wants to merge 4 commits into
apache:mainfrom
aws-mwaa:ghaeli/callback-jinja-rendering-v2
Draft

Add Jinja template rendering for deadline callback kwargs#68408
seanghaeli wants to merge 4 commits into
apache:mainfrom
aws-mwaa:ghaeli/callback-jinja-rendering-v2

Conversation

@seanghaeli

@seanghaeli seanghaeli commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-on to #66608 (when that's merged this will be 25 line PR, just wanted to have it up now). Now that deadline callbacks receive a full context at runtime, render Jinja templates in the callback's string kwargs against that context before invoking the callback.

DeadlineAlert(
    ...,
    callback=SyncCallback(notify),
    callback_kwargs={"text": "DAG {{ dag_run.dag_id }} missed at {{ deadline.deadline_time }}"},
)

What

  • _render_callback_kwargs() renders string kwargs containing {{ against the callback context (dag_run, deadline, run_id, ds, ts, etc.) just before the callback is invoked.
  • Non-string values, the context key itself, and strings without template markers pass through unchanged.
  • Render failures fall back to the raw string with a warning — a bad template never crashes the callback.
  • Notifier classes (BaseNotifier subclasses) are unaffected; they handle their own rendering via __call__.

Testing

  • 6 unit tests: single template, multiple kwargs, non-string skip, no-marker skip, deadline context resolution, graceful fallback on invalid template (all passing).
  • Verified end-to-end in Breeze: "Deadline {{ deadline.deadline_time }} missed for {{ dag_run.dag_id }}" rendered to real values through a live triggerer + scheduler run.

Sean Ghaeli added 4 commits June 9, 2026 20:55
When a deadline callback fires, it now fetches DagRun context from the
Execution API and passes it to the callback as context["deadline"] and
context["dag_run"]. This enables Jinja template rendering ({{ dag_run }},
{{ deadline.deadline_time }}) and enriched notifications.

Key changes:
- Add GetDagRun comms message and handler in callback supervisor
- Wire dag_id/run_id/deadline_id/deadline_time through the workload path
- Build context dict from DagRun response via build_context_from_dag_run
- Fail callback (for retry) when context fetch fails instead of running
  degraded
- Restrict token:workload to read-only Execution API routes (GET only)
- Add hash verification in _ensure_bundle_module_registered to prevent
  wrong-bundle loading when multiple bundles share a filename
- Run bundle initialization off triggerer event loop (asyncio.to_thread)
- Extract _load_mangled_module to airflow._shared.module_loading as a
  shared helper for both triggerer and executor paths
Plain function callbacks can now use Jinja2 templates in their kwargs:

    callback_kwargs={"text": "DAG {{ dag_run.dag_id }} missed at {{ deadline.deadline_time }}"}

String values containing `{{` are rendered against the callback context
(which includes dag_run, deadline, run_id, ds, ts, etc.) before the
callback is invoked. Non-string values, the context key itself, and
strings without template markers pass through unchanged. Render failures
fall back to the raw string with a warning.

Notifier classes (BaseNotifier subclasses) are unaffected — they handle
their own rendering via __call__.
@boring-cyborg boring-cyborg Bot added area:API Airflow's REST/HTTP API area:deadline-alerts AIP-86 (former AIP-57) area:Executors-core LocalExecutor & SequentialExecutor area:providers area:task-sdk area:Triggerer provider:amazon AWS/Amazon - related issues labels Jun 11, 2026
@seanghaeli seanghaeli closed this Jun 11, 2026
@seanghaeli seanghaeli reopened this Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API area:deadline-alerts AIP-86 (former AIP-57) area:Executors-core LocalExecutor & SequentialExecutor area:providers area:task-sdk area:Triggerer provider:amazon AWS/Amazon - related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant