-
Notifications
You must be signed in to change notification settings - Fork 14.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added exception catching to send default email if template file raises any exception #24943
Conversation
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 Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
|
A test failed, but I'd like to argue my case: In this try - except we will mostly catch the FileNotFoundError, which is explicit. In any other case (e.g. an IO error), I believe we should still send the email with the default template to make sure we are always notified. |
Yeah. I'd agree. Please add tests covering it and fix those that failed. |
airflow/models/taskinstance.py
Outdated
content = f.read() | ||
except FileNotFoundError: | ||
self.log.warning(f"Could not find email template file '{path}'. Using defaults...") | ||
except: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1 to this blank catch. It’s probably worthwhile to catch all OSError, but this is way to broad.
airflow/models/taskinstance.py
Outdated
with open(path) as f: | ||
content = f.read() | ||
except FileNotFoundError: | ||
self.log.warning(f"Could not find email template file '{path}'. Using defaults...") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to use {path!r}
Follwing @uranusjr advice, I replaced the broad exception to only catch OSError (which is the only one that should happen, actually). I have also added a UnitTest:
With this changes, the PR should be ready to be merged. |
Only static checks already fixed in main are failing. MErging. |
Awesome work, congrats on your first merged pull request! |
This PR closes #24919
A try - except block has been added to prevent email failure when a custom template file is used for task error notifications.
Although once Airflow has been correctly configured we should never need the except block, sometimes we may encounter issues when updating the template file. I believe Airflow should always send the email and, in case the template file has any problems, it should just send the default template.