Skip to content

Skip notifier templating with empty template_fields#64993

Open
DaveT1991 wants to merge 2 commits intoapache:v3-1-stablefrom
DaveT1991:fix/notifier-local-dags-test
Open

Skip notifier templating with empty template_fields#64993
DaveT1991 wants to merge 2 commits intoapache:v3-1-stablefrom
DaveT1991:fix/notifier-local-dags-test

Conversation

@DaveT1991
Copy link
Copy Markdown
Contributor

@DaveT1991 DaveT1991 commented Apr 10, 2026

Summary

Skip notifier templating setup when a notifier does not define any template fields.

When airflow dags test executes DAG callbacks, the callback context can include a SerializedDAG. BaseNotifier.render_template_fields() currently always requests a template environment from the context DAG, even when there is nothing to render. For notifiers that rely on the default empty template_fields, that raises AttributeError before the callback can run.

This change returns early when template_fields is empty and adds a regression test that exercises a notifier callback with a serialized DAG context.

Closes #64649

Testing

  • Added a regression test in task-sdk/tests/task_sdk/bases/test_notifier.py
  • git diff --check

@boring-cyborg
Copy link
Copy Markdown

boring-cyborg bot commented Apr 10, 2026

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@DaveT1991
Copy link
Copy Markdown
Contributor Author

Any updates about my code submission?

@kaxil kaxil requested a review from Copilot April 10, 2026 19:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes notifier callbacks failing under airflow dags test when the callback context contains a SerializedDAG by avoiding unnecessary Jinja environment setup when there are no template fields to render.

Changes:

  • Return early from BaseNotifier.render_template_fields() when template_fields is empty.
  • Avoid calling dag.get_template_env() when the context DAG object doesn’t support it (e.g., SerializedDAG), falling back to a default environment.
  • Add regression tests covering notifier invocation and template rendering with a serialized DAG in the context.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
task-sdk/src/airflow/sdk/bases/notifier.py Skips templating work when template_fields is empty; adds safer template-env selection for non-DAG context objects.
task-sdk/tests/task_sdk/bases/test_notifier.py Adds regression tests for notifier callback execution and template rendering when context["dag"] is a SerializedDAG.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants