ITJamie commented on code in PR #31216:
URL: https://github.com/apache/airflow/pull/31216#discussion_r1192851108


##########
airflow/utils/email.py:
##########
@@ -241,27 +241,33 @@ def send_mime_email(
     smtp_user = None
     smtp_password = None
 
+    found_email_connection = False
     if conn_id is not None:
         try:
             from airflow.hooks.base import BaseHook
 
             airflow_conn = BaseHook.get_connection(conn_id)
             smtp_user = airflow_conn.login
             smtp_password = airflow_conn.password
+            found_email_connection = True
         except AirflowException:
             pass
-    if smtp_user is None or smtp_password is None:
-        warnings.warn(
-            "Fetching SMTP credentials from configuration variables will be 
deprecated in a future "
-            "release. Please set credentials using a connection instead.",
-            RemovedInAirflow3Warning,
-            stacklevel=2,
-        )
+    if not found_email_connection:
         try:
             smtp_user = conf.get("smtp", "SMTP_USER")
             smtp_password = conf.get("smtp", "SMTP_PASSWORD")
         except AirflowConfigException:
-            log.debug("No user/password found for SMTP, so logging in with no 
authentication.")
+            pass
+        # if at this point smtp_user or smtp_password is set it came from 
conf.get, trigger warning
+        if smtp_user is not None or smtp_password is not None:
+            warnings.warn(
+                "Fetching SMTP credentials from configuration variables will 
be deprecated in a future "
+                "release. Please set credentials using a connection instead.",
+                RemovedInAirflow3Warning,
+                stacklevel=2,
+            )
+    if smtp_user is None or smtp_password is None:
+        log.debug("No user/password found for SMTP, so logging in with no 
authentication.")

Review Comment:
   We want it to trigger after ether a connection has been found or failback to 
airflow.cfg variables have been parsed
   
   So i moved it after the above had been completed



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to