Skip to content

fix stmp email callback to use email_conn_id#65072

Open
wjddn279 wants to merge 1 commit intoapache:mainfrom
wjddn279:fix-stmp-email-callback
Open

fix stmp email callback to use email_conn_id#65072
wjddn279 wants to merge 1 commit intoapache:mainfrom
wjddn279:fix-stmp-email-callback

Conversation

@wjddn279
Copy link
Copy Markdown
Contributor

@wjddn279 wjddn279 commented Apr 12, 2026

Closes: #65012

Updated to read email_conn_id as the default connection ID for SmtpHook, in order to maintain backward compatibility with the existing functionality.


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

Copy link
Copy Markdown
Contributor

@henry3260 henry3260 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! LGTM!

@wjddn279
Copy link
Copy Markdown
Contributor Author

@amoghrajesh

Can you check this pr? and this question related issue
#65012 (comment)

Copy link
Copy Markdown
Contributor

@amoghrajesh amoghrajesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a real bug, thanks for solving this.

I have some comments.

super().__init__(**kwargs)
else:
super().__init__()
self.smtp_conn_id = smtp_conn_id
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we instead do this during instantiation time? Like this

Suggested change
self.smtp_conn_id = smtp_conn_id or conf.get("email", "email_conn_id", fallback=SmtpHook.default_conn_name)

mime_charset: str = "utf-8",
custom_headers: dict[str, Any] | None = None,
smtp_conn_id: str = SmtpHook.default_conn_name,
smtp_conn_id: str = conf.get("email", "email_conn_id", fallback=SmtpHook.default_conn_name),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
smtp_conn_id: str = conf.get("email", "email_conn_id", fallback=SmtpHook.default_conn_name),
smtp_conn_id: str | None = None,

Comment on lines +226 to +245
def test_notifier_default_smtp_conn_id_from_config(self):
"""Test that smtp_conn_id defaults to email.email_conn_id from config."""
import importlib

import airflow.providers.smtp.notifications.smtp as smtp_mod

from tests_common.test_utils.config import conf_vars

with conf_vars({("email", "email_conn_id"): "config_smtp_conn"}):
importlib.reload(smtp_mod)
try:
notifier = smtp_mod.SmtpNotifier(
to=TEST_RECEIVER,
from_email=TEST_SENDER,
subject=TEST_SUBJECT,
html_content=TEST_BODY,
)
assert notifier.smtp_conn_id == "config_smtp_conn"
finally:
importlib.reload(smtp_mod)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is masking the instantiation problem I mentioned earlier. You have to reload the module for things to take affect.

Instead, after the fix, the test would be as simple as:

def test_notifier_default_smtp_conn_id_from_config(self):
    """Test that smtp_conn_id defaults to email.email_conn_id from config."""
    with conf_vars({("email", "email_conn_id"): "config_smtp_conn"}):
        notifier = SmtpNotifier(
            to=TEST_RECEIVER,
            from_email=TEST_SENDER,
            subject=TEST_SUBJECT,
            html_content=TEST_BODY,
        )
        assert notifier.smtp_conn_id == "config_smtp_conn"

subject=subject,
html_content=html_content,
from_email=conf.get("email", "from_email", fallback="airflow@airflow"),
smtp_conn_id=conf.get("email", "email_conn_id", fallback=SmtpHook.default_conn_name),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With my above comment, the default will be handled in provider code, so no need to pass fallback here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Airflow 3.2.0 doesn't use anymore configured email_backend for "email_on_failure"

3 participants