You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "sameerpandey17 (via GitHub)" <gi...@apache.org> on 2026/10/18 08:48:40 UTC

[PR] Fix notifier crash when callback receives a SerializedDAG [airflow]

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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix notifier crash when callback receives a SerializedDAG [airflow]

Posted by "sameerpandey17 (via GitHub)" <gi...@apache.org>.
sameerpandey17 commented on code in PR #74973:
URL: https://github.com/apache/airflow/pull/74973#discussion_r4308598682


##########
task-sdk/tests/task_sdk/bases/test_notifier.py:
##########
@@ -97,3 +97,35 @@ def test_notifier_call_with_prepared_context(self, caplog):
             }
         )
         assert notifier.message == "task: some_task"
+
+    def test_render_template_fields_with_dag_without_get_template_env(self):
+        """Notifier must not crash when context['dag'] has no get_template_env (e.g. SerializedDAG)."""
+
+        class _FakeDag:

Review Comment:
   Switched both tests to a real `SerializedDAG` via `create_scheduler_dag` and dropped the stand-in class (3bfb401)
   



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix notifier crash when callback receives a SerializedDAG [airflow]

Posted by "sameerpandey17 (via GitHub) via commits" <co...@airflow.apache.org>.
sameerpandey17 commented on PR #74973:
URL: https://github.com/apache/airflow/pull/74973#issuecomment-6722247201

   @ashb CI is failing at “Build CI images” (Python 3.11) with an apt conflict in install_os_dependencies.sh: libffi-dev requires libffi8 (= 3.4.8-2+deb13u0+dhi2) but 3.4.8-2+dhi2 is installed. It failed again on the re-run. My change only touches task-sdk, so it looks unrelated, and recent runs on main look green now. 
   Could you re-run the failed jobs when you have a moment? Thanks!


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix notifier crash when callback receives a SerializedDAG [airflow]

Posted by "SameerMesiah97 (via GitHub)" <gi...@apache.org>.
SameerMesiah97 commented on code in PR #74973:
URL: https://github.com/apache/airflow/pull/74973#discussion_r4307499327


##########
task-sdk/tests/task_sdk/bases/test_notifier.py:
##########
@@ -97,3 +97,35 @@ def test_notifier_call_with_prepared_context(self, caplog):
             }
         )
         assert notifier.message == "task: some_task"
+
+    def test_render_template_fields_with_dag_without_get_template_env(self):
+        """Notifier must not crash when context['dag'] has no get_template_env (e.g. SerializedDAG)."""
+
+        class _FakeDag:

Review Comment:
   Why not use an actual `SerializedDag` instead of a simulated object? This is better than no tests but it doesn’t establish that the real object involved in the reported failure works through the notifier path



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix notifier crash when callback receives a SerializedDAG [airflow]

Posted by "sameerpandey17 (via GitHub)" <gi...@apache.org>.
sameerpandey17 commented on code in PR #74973:
URL: https://github.com/apache/airflow/pull/74973#discussion_r4308025084


##########
task-sdk/tests/task_sdk/bases/test_notifier.py:
##########
@@ -97,3 +97,35 @@ def test_notifier_call_with_prepared_context(self, caplog):
             }
         )
         assert notifier.message == "task: some_task"
+
+    def test_render_template_fields_with_dag_without_get_template_env(self):
+        """Notifier must not crash when context['dag'] has no get_template_env (e.g. SerializedDAG)."""
+
+        class _FakeDag:

Review Comment:
   oh yeah that makes sense!
   thanks for the suggestion , i have made the new test and i'm testing things right now , i'll commit it soon
   



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix notifier crash when callback receives a SerializedDAG [airflow]

Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #74973:
URL: https://github.com/apache/airflow/pull/74973#issuecomment-6247859606

   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](https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
   Here are some useful points:
   - Pay attention to the quality of your code (ruff, mypy and type annotations). Our [prek-hooks]( https://github.com/apache/airflow/blob/main/contributing-docs/08_static_code_checks.rst#prerequisites-for-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](https://github.com/apache/airflow/blob/main/airflow-core/docs/howto/custom-operator.rst) Consider adding an example Dag that shows how users should use it.
   - Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/dev/breeze/doc/README.rst) 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](https://www.apache.org/foundation/policies/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]( https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#coding-style-and-best-practices).
   - 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
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org