This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 84a8f7ecc1 Fix backwards compatibility for SMTP provider (#37701)
84a8f7ecc1 is described below
commit 84a8f7ecc122e9b63d4d2834ee8994587c467eb2
Author: Jarek Potiuk <[email protected]>
AuthorDate: Mon Feb 26 13:21:11 2024 +0100
Fix backwards compatibility for SMTP provider (#37701)
The #36226 introduced backwards compatibility check for the smtp
provider, where it relied pn airflow settings containig new settings.
This PR fixes it by falling back to default settings in case the
settings cannot be imported.
---
airflow/providers/smtp/notifications/smtp.py | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/airflow/providers/smtp/notifications/smtp.py
b/airflow/providers/smtp/notifications/smtp.py
index ce977152e2..59877ee29a 100644
--- a/airflow/providers/smtp/notifications/smtp.py
+++ b/airflow/providers/smtp/notifications/smtp.py
@@ -25,6 +25,24 @@ from airflow.configuration import conf
from airflow.notifications.basenotifier import BaseNotifier
from airflow.providers.smtp.hooks.smtp import SmtpHook
+try:
+ from airflow.settings import SMTP_DEFAULT_TEMPLATED_HTML_CONTENT_PATH,
SMTP_DEFAULT_TEMPLATED_SUBJECT
+except ImportError:
+ # This is a fallback for when the settings are not available - they were
only added in 2.8.1,
+ # so we should be able to remove it when min airflow version for the SMTP
provider is 2.9.0
+ # we do not raise deprecation warning here, because the user might be
using 2.8.0 and the new provider
+ # deliberately, and we do not want to upgrade to newer version of Airflow
so we should not raise the
+ # deprecation warning here. If the user will modify the settings in
local_settings even for earlier
+ # versions of Airflow, they will be properly used as they will be imported
above
+ SMTP_DEFAULT_TEMPLATED_HTML_CONTENT_PATH = (Path(__file__).parent /
"templates" / "email.html").as_posix()
+ SMTP_DEFAULT_TEMPLATED_SUBJECT = """
+{% if ti is defined %}
+DAG {{ ti.dag_id }} - Task {{ ti.task_id }} - Run ID {{ ti.run_id }} in State
{{ ti.state }}
+{% elif slas is defined %}
+SLA Missed for DAG {{ dag.dag_id }} - Task {{ slas[0].task_id }}
+{% endif %}
+"""
+
class SmtpNotifier(BaseNotifier):
"""
@@ -82,8 +100,6 @@ class SmtpNotifier(BaseNotifier):
*,
template: str | None = None,
):
- from airflow.settings import SMTP_DEFAULT_TEMPLATED_HTML_CONTENT_PATH,
SMTP_DEFAULT_TEMPLATED_SUBJECT
-
super().__init__()
self.smtp_conn_id = smtp_conn_id
self.from_email = from_email or conf.get("smtp", "smtp_mail_from")