Skip to content

Add Jinja template rendering for async deadline callbacks#66496

Closed
seanghaeli wants to merge 2 commits into
apache:mainfrom
aws-mwaa:ghaeli/async-callback-template-rendering
Closed

Add Jinja template rendering for async deadline callbacks#66496
seanghaeli wants to merge 2 commits into
apache:mainfrom
aws-mwaa:ghaeli/async-callback-template-rendering

Conversation

@seanghaeli
Copy link
Copy Markdown
Contributor

@seanghaeli seanghaeli commented May 6, 2026

Summary

Add Jinja template rendering support for async deadline callbacks running in the triggerer. Uses Airflow's standard render_template() (via BaseTriggerTemplater) rather than raw Jinja, and correctly skips rendering for Notifiers which handle their own template fields.

Builds on the simple context introduced in #55241, with a clear path toward full Execution API context fetching documented as a follow-up.

Changes

  • Add template rendering in CallbackTrigger.run() using inherited render_template()
  • Add _is_notifier_class() duck-typing helper to skip double-rendering for Notifiers
  • Remove unnecessary selectinload(Deadline.deadline_alert) from scheduler query
  • Add comprehensive tests: template rendering, nested rendering, notifier handling, serialization regression
  • Update TODOs documenting the Execution API path forward

Related

Renders Jinja2 templates in callback kwargs using the simple context
(dag_run, deadline info) that the scheduler passes to the triggerer.
This allows users to write callbacks like:

    AsyncCallback(my_func, kwargs={"msg": "DAG {{ dag_id }} missed deadline"})

Key design decisions:
- Uses BaseTrigger's inherited render_template() (via Templater) for
  consistent rendering behavior with the rest of Airflow
- Skips pre-rendering for Notifier classes since they handle their own
  template rendering in __await__ via render_template_fields()
- Only renders when context is present (no-op for callbacks without context)
- Acknowledges this is interim: full context should be fetched via the
  Execution API at execution time (tracked in PR apache#64984 TODO comments)

Addresses feedback from Ramit (PR apache#64984 comment) by documenting the
path forward while still providing template rendering value on top of
the existing simple context from PR apache#55241.
@boring-cyborg boring-cyborg Bot added the area:deadline-alerts AIP-86 (former AIP-57) label May 6, 2026
@seanghaeli seanghaeli marked this pull request as ready for review May 7, 2026 01:52
@seanghaeli seanghaeli requested review from XD-DENG and ashb as code owners May 7, 2026 01:52
@seanghaeli
Copy link
Copy Markdown
Contributor Author

Closing this PR — the approach of building template rendering on top of the stored simple context doesn't address the architectural concern that context shouldn't be stored in the DB at all. The proper implementation should fetch full context via the Execution API at callback execution time (now possible since #55068 merged), which means reverting the simple context from #55241 and replacing it with runtime context fetching. Will reopen with the correct approach.

@seanghaeli seanghaeli closed this May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:deadline-alerts AIP-86 (former AIP-57)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant