kyan113 opened a new issue #22152: URL: https://github.com/apache/airflow/issues/22152
### Apache Airflow version 2.2.4 (latest released) ### What happened A DAG constructed with render_template_as_native_obj=True does not send an e-mail notification on task failure. DAGs constructed without render_template_as_native_obj send e-mail notification as expected. default_email_on_failure is set to True in airflow.cfg. ### What you expected to happen I expect DAGs to send an e-mail alert on task failure. Logs for failed tasks show this: ``` Traceback (most recent call last): File "/home/airflow/.local/lib/python3.9/site-packages/airflow/models/taskinstance.py", line 1767, in handle_failure self.email_alert(error) File "/home/airflow/.local/lib/python3.9/site-packages/airflow/models/taskinstance.py", line 2101, in email_alert subject, html_content, html_content_err = self.get_email_subject_content(exception) File "/home/airflow/.local/lib/python3.9/site-packages/airflow/models/taskinstance.py", line 2093, in get_email_subject_content subject = render('subject_template', default_subject) File "/home/airflow/.local/lib/python3.9/site-packages/airflow/models/taskinstance.py", line 2091, in render return render_template_to_string(jinja_env.from_string(content), jinja_context) File "/home/airflow/.local/lib/python3.9/site-packages/airflow/utils/helpers.py", line 268, in render_template_to_string return render_template(template, context, native=False) File "/home/airflow/.local/lib/python3.9/site-packages/airflow/utils/helpers.py", line 263, in render_template return "".join(nodes) TypeError: sequence item 1: expected str instance, TaskInstance found ``` ### How to reproduce 1. Construct a DAG with render_template_as_native_obj=True with 'email_on_failure':True. 2. Cause an error in a task. I used a PythonOperator with `assert False`. 3. Task will fail, but no alert e-mail will be sent. 4. Remove render_template_as_native_obj=True from DAG constructor. 5. Re-run DAG 6. Task will fail and alert e-mail will be sent. I used the following for testing: ``` import datetime from airflow.operators.python_operator import PythonOperator from airflow.models import DAG default_args = { 'owner': 'me', 'start_date': datetime.datetime(2022,3,9), 'email_on_failure':True, 'email':'myem...@email.com' } dag = DAG(dag_id = 'dagname', schedule_interval = '@once', default_args = default_args, render_template_as_native_obj = True, #comment this out to test ) def testfunc(**kwargs): #intentional error assert False task_testfunc = PythonOperator( task_id = "task_testfunc", python_callable=testfunc, dag=dag) task_testfunc ``` ### Operating System Red Hat Enterprise Linux Server 7.9 (Maipo) ### Versions of Apache Airflow Providers _No response_ ### Deployment Docker-Compose ### Deployment details _No response_ ### Anything else _No response_ ### Are you willing to submit PR? - [ ] Yes I am willing to submit a PR! ### Code of Conduct - [X] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md) -- 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-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org