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 2018/09/11 19:01:26 UTC

[GitHub] r39132 closed pull request #3869: [AIRFLOW-3012] Fix Bug when passing emails for SLA

r39132 closed pull request #3869: [AIRFLOW-3012] Fix Bug when passing emails for SLA
URL: https://github.com/apache/incubator-airflow/pull/3869
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/airflow/jobs.py b/airflow/jobs.py
index 90dd293f1e..916ec1f243 100644
--- a/airflow/jobs.py
+++ b/airflow/jobs.py
@@ -58,7 +58,7 @@
                                           SimpleDagBag,
                                           list_py_file_paths)
 from airflow.utils.db import create_session, provide_session
-from airflow.utils.email import send_email
+from airflow.utils.email import send_email, get_email_address_list
 from airflow.utils.log.logging_mixin import LoggingMixin, set_context, StreamLogWriter
 from airflow.utils.net import get_hostname
 from airflow.utils.state import State
@@ -711,7 +711,7 @@ def manage_slas(self, dag, session=None):
             for task in dag.tasks:
                 if task.email:
                     if isinstance(task.email, basestring):
-                        emails.add(task.email)
+                        emails |= set(get_email_address_list(task.email))
                     elif isinstance(task.email, (list, tuple)):
                         emails |= set(task.email)
             if emails and len(slas):
diff --git a/airflow/utils/email.py b/airflow/utils/email.py
index f4038715ac..d26ffb8a70 100644
--- a/airflow/utils/email.py
+++ b/airflow/utils/email.py
@@ -47,6 +47,9 @@ def send_email(to, subject, html_content,
     path, attr = configuration.conf.get('email', 'EMAIL_BACKEND').rsplit('.', 1)
     module = importlib.import_module(path)
     backend = getattr(module, attr)
+    to = get_email_address_list(to)
+    to = ", ".join(to)
+
     return backend(to, subject, html_content, files=files,
                    dryrun=dryrun, cc=cc, bcc=bcc,
                    mime_subtype=mime_subtype, mime_charset=mime_charset, **kwargs)
@@ -128,9 +131,9 @@ def send_MIME_email(e_from, e_to, mime_msg, dryrun=False):
 def get_email_address_list(address_string):
     if isinstance(address_string, basestring):
         if ',' in address_string:
-            address_string = address_string.split(',')
+            address_string = [address.strip() for address in address_string.split(',')]
         elif ';' in address_string:
-            address_string = address_string.split(';')
+            address_string = [address.strip() for address in address_string.split(';')]
         else:
             address_string = [address_string]
 
diff --git a/tests/utils/test_email.py b/tests/utils/test_email.py
new file mode 100644
index 0000000000..1666ef5c62
--- /dev/null
+++ b/tests/utils/test_email.py
@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import unittest
+from airflow.utils.email import get_email_address_list
+
+EMAILS = ['test1@example.com', 'test2@example.com']
+
+
+class EmailTest(unittest.TestCase):
+
+    def test_get_email_address_comma_sep_string(self):
+        emails_string = 'test1@example.com, test2@example.com'
+
+        self.assertEquals(
+            get_email_address_list(emails_string), EMAILS)
+
+    def test_get_email_address_colon_sep_string(self):
+        emails_string = 'test1@example.com; test2@example.com'
+
+        self.assertEquals(
+            get_email_address_list(emails_string), EMAILS)
+
+    def test_get_email_address_list(self):
+        emails_list = ['test1@example.com', 'test2@example.com']
+
+        self.assertEquals(
+            get_email_address_list(emails_list), EMAILS)


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services