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

   closes: #64649
   related: #64993
   related: #67862
   
   Under `airflow dags test`, `on_failure_callback` receives a `SerializedDAG`, 
which has no `get_template_env`. `BaseNotifier.render_template_fields` passes 
it to `Templater.get_template_env`, which calls that method unconditionally, so 
the callback fails with `AttributeError` and `notify()` is never called. I 
reproduced this on main (`7f0d50cffc`) with a notifier that has no 
`template_fields` and one that has `template_fields = ("message",)`.
   
   `Templater.get_template_env` now uses the Dag's environment only if the Dag 
has `get_template_env`, and otherwise returns the default sandboxed environment 
it already uses when there is no Dag. Real `DAG` objects behave as before. The 
fallback has no Dag-level macros, filters or search path (from reading the 
code, not tested), and I only verified the `dags test` path.
   
   Testing: two new tests in `task-sdk/tests/task_sdk/bases/test_notifier.py` 
use a stand-in dag without `get_template_env`; both fail with the 
`AttributeError` without the change and pass with it. The existing notifier 
tests still pass (7 passed). I also ran `airflow dags test` in Breeze with both 
notifier shapes: crash before, normal run after.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: Claude Sonnet 4.6 (writing the tests), Claude Sonnet 5.5 
(investigation, planning and drafting the PR text) following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)


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