You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/03/10 16:13:20 UTC
[GitHub] [airflow] kyan113 opened a new issue #22152: render_template_as_native_obj=True in DAG constructor prevents failure e-mail from sending
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':'myemail@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-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] likecodingloveproblems edited a comment on issue #22152: render_template_as_native_obj=True in DAG constructor prevents failure e-mail from sending
Posted by GitBox <gi...@apache.org>.
likecodingloveproblems edited a comment on issue #22152:
URL: https://github.com/apache/airflow/issues/22152#issuecomment-1066153902
Would I work on this issue please?
--
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
[GitHub] [airflow] boring-cyborg[bot] commented on issue #22152: render_template_as_native_obj=True in DAG constructor prevents failure e-mail from sending
Posted by GitBox <gi...@apache.org>.
boring-cyborg[bot] commented on issue #22152:
URL: https://github.com/apache/airflow/issues/22152#issuecomment-1064231787
Thanks for opening your first issue here! Be sure to follow the issue template!
--
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
[GitHub] [airflow] uranusjr commented on issue #22152: render_template_as_native_obj=True in DAG constructor prevents failure e-mail from sending
Posted by GitBox <gi...@apache.org>.
uranusjr commented on issue #22152:
URL: https://github.com/apache/airflow/issues/22152#issuecomment-1066206647
Please also see #22218 for some context.
--
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
[GitHub] [airflow] uranusjr commented on issue #22152: render_template_as_native_obj=True in DAG constructor prevents failure e-mail from sending
Posted by GitBox <gi...@apache.org>.
uranusjr commented on issue #22152:
URL: https://github.com/apache/airflow/issues/22152#issuecomment-1065396889
Would you fancy a pull request please? The fix should be fairly straightforward, by changing the offending line in `render_template` to this:
```python
return "".join((str(n) for n in nodes)
```
Add a test can be added to ensure `render_template` works with non-str nodes.
--
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
[GitHub] [airflow] likecodingloveproblems commented on issue #22152: render_template_as_native_obj=True in DAG constructor prevents failure e-mail from sending
Posted by GitBox <gi...@apache.org>.
likecodingloveproblems commented on issue #22152:
URL: https://github.com/apache/airflow/issues/22152#issuecomment-1066153902
Would I work on this issue?
--
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
[GitHub] [airflow] kyan113 commented on issue #22152: render_template_as_native_obj=True in DAG constructor prevents failure e-mail from sending
Posted by GitBox <gi...@apache.org>.
kyan113 commented on issue #22152:
URL: https://github.com/apache/airflow/issues/22152#issuecomment-1066172041
If you'd like. I don't think I have the expertise to put together a pull request, so someone else will need to take a crack at it.
--
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
[GitHub] [airflow] andyfcx commented on issue #22152: render_template_as_native_obj=True in DAG constructor prevents failure e-mail from sending
Posted by GitBox <gi...@apache.org>.
andyfcx commented on issue #22152:
URL: https://github.com/apache/airflow/issues/22152#issuecomment-1066045310
I think `return "".join((str(n) for n in nodes) `
might not work due to possible returning as generator string representations
--
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