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
- Construct a DAG with render_template_as_native_obj=True with 'email_on_failure':True.
- Cause an error in a task. I used a PythonOperator with
assert False.
- Task will fail, but no alert e-mail will be sent.
- Remove render_template_as_native_obj=True from DAG constructor.
- Re-run DAG
- 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':'[email protected]'
}
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?
Code of Conduct
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:
How to reproduce
assert False.I used the following for testing:
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?
Code of Conduct