Repository navigation
Deprecate airflow.utils.email in favor of the SMTP provider - #75414
Conversation
|
This PR raises core's minimum Also, Drafted-by: Claude Code (Opus 5.5); reviewed by @shivaam before posting |
|
@hussein-awala could you help me review this PR? |
Shouldn't we deprecate the core email settings as part of this PR? |
Not yet. The SMTP provider's emailer reads the Plan:
The Drafted-by: Claude Code (Opus 5.5); reviewed by @shivaam before posting |
amoghrajesh
left a comment
There was a problem hiding this comment.
A deprecated public module plus a provider floor going 2.3.1 to 3.2.0 is upgrade-relevant, so significant newsfragment pls.
Added Drafted-by: Claude Code (Opus 5.5); reviewed by @shivaam before posting |
fabb999 to
ac7c012
Compare
amoghrajesh
left a comment
There was a problem hiding this comment.
Thanks for working on a rather difficult task @shivaam! LGTM
Two providers still import the deprecated module: amazon/aws/hooks/ses.py and sendgrid/utils/emailer.py.
Once this merges, anyone using SesHook gets a import time warning. And all they can do is upgrade to correct airflow for this. Both providers will now need the SMTP provider installed to import at all, and they should declare in dependencies.
The right next step here would be to clean this up
Thanks! The SES and SendGrid PRs are ready: each provider gets its own copy of the helper, so neither imports Drafted-by: Claude Code (Opus 5.5); reviewed by @shivaam before posting |
The email utilities now live in airflow.providers.smtp.utils.emailer. airflow.utils.email keeps its public names as deprecated aliases of the provider functions, so existing imports and email_backend settings keep working with a DeprecatedImportWarning. The default [email] email_backend value is unchanged. The Task SDK treats it as "no custom backend" and sends alerts with SmtpNotifier, as before. A regression test covers email sent from a server process, such as a listener in the API server, with the SMTP login stored only in the metadata database. airflow-core now requires apache-airflow-providers-smtp>=3.2.0, the first release that contains the emailer module.
"from airflow.utils.email import *" imported the email functions before they moved to the SMTP provider. Listing them in __all__ keeps that import working, with the same deprecation warning as named imports. The email configuration guide now says where the functions live, that the default email_backend value is unchanged, and that the moved functions do not see settings changed at runtime with airflow.configuration.conf.set(). The coverage script entry for airflow/utils/email.py is left unchanged, so this change stays within airflow-core.
The SMTP server and connection setup is documented by the SMTP provider, so the core page now only explains email_backend and the [email] options shared by all backends, and links to the provider docs.
Add a significant newsfragment, keep email_backend at its default in the docs note, and name the Connection lookup and configuration source in the deprecation warning.
Outside task and server processes the Connection lookup only searches environment variables and secrets backends, so the email is sent without a login. The newsfragment describes this; the test now covers it.
af5c809 to
f327acd
Compare
Backport successfully created: v3-4-testNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
|
…er (#75414) * Deprecate airflow.utils.email in favor of the SMTP provider The email utilities now live in airflow.providers.smtp.utils.emailer. airflow.utils.email keeps its public names as deprecated aliases of the provider functions, so existing imports and email_backend settings keep working with a DeprecatedImportWarning. The default [email] email_backend value is unchanged. The Task SDK treats it as "no custom backend" and sends alerts with SmtpNotifier, as before. A regression test covers email sent from a server process, such as a listener in the API server, with the SMTP login stored only in the metadata database. airflow-core now requires apache-airflow-providers-smtp>=3.2.0, the first release that contains the emailer module. * Keep star imports of airflow.utils.email working and document the move "from airflow.utils.email import *" imported the email functions before they moved to the SMTP provider. Listing them in __all__ keeps that import working, with the same deprecation warning as named imports. The email configuration guide now says where the functions live, that the default email_backend value is unchanged, and that the moved functions do not see settings changed at runtime with airflow.configuration.conf.set(). The coverage script entry for airflow/utils/email.py is left unchanged, so this change stays within airflow-core. * Shorten the core email page and point to the SMTP provider docs The SMTP server and connection setup is documented by the SMTP provider, so the core page now only explains email_backend and the [email] options shared by all backends, and links to the provider docs. * Explain what changes for callers of the deprecated email functions Add a significant newsfragment, keep email_backend at its default in the docs note, and name the Connection lookup and configuration source in the deprecation warning. * Test that a plain script does not see a database-only SMTP Connection Outside task and server processes the Connection lookup only searches environment variables and secrets backends, so the email is sent without a login. The newsfragment describes this; the test now covers it. (cherry picked from commit ad6ec79) Co-authored-by: Shivam Rastogi <6463385+shivaam@users.noreply.github.com>
airflow-core now requires providers-smtp>=3.2.0 (email deprecation, #75414/#75709). The emailer source landed via #75704 but the in-repo provider version was still 3.1.1, so the CI image build failed resolving the floor. Mirrors the smtp slice of the 3.2.0 provider release (#75209): version + provider.yaml + changelog + doc refs.
…er (#75414) (#75709) * Deprecate airflow.utils.email in favor of the SMTP provider The email utilities now live in airflow.providers.smtp.utils.emailer. airflow.utils.email keeps its public names as deprecated aliases of the provider functions, so existing imports and email_backend settings keep working with a DeprecatedImportWarning. The default [email] email_backend value is unchanged. The Task SDK treats it as "no custom backend" and sends alerts with SmtpNotifier, as before. A regression test covers email sent from a server process, such as a listener in the API server, with the SMTP login stored only in the metadata database. airflow-core now requires apache-airflow-providers-smtp>=3.2.0, the first release that contains the emailer module. * Keep star imports of airflow.utils.email working and document the move "from airflow.utils.email import *" imported the email functions before they moved to the SMTP provider. Listing them in __all__ keeps that import working, with the same deprecation warning as named imports. The email configuration guide now says where the functions live, that the default email_backend value is unchanged, and that the moved functions do not see settings changed at runtime with airflow.configuration.conf.set(). The coverage script entry for airflow/utils/email.py is left unchanged, so this change stays within airflow-core. * Shorten the core email page and point to the SMTP provider docs The SMTP server and connection setup is documented by the SMTP provider, so the core page now only explains email_backend and the [email] options shared by all backends, and links to the provider docs. * Explain what changes for callers of the deprecated email functions Add a significant newsfragment, keep email_backend at its default in the docs note, and name the Connection lookup and configuration source in the deprecation warning. * Test that a plain script does not see a database-only SMTP Connection Outside task and server processes the Connection lookup only searches environment variables and secrets backends, so the email is sent without a login. The newsfragment describes this; the test now covers it. (cherry picked from commit ad6ec79) Co-authored-by: Shivam Rastogi <6463385+shivaam@users.noreply.github.com>
The backport of #75414 (#75709) raised the SMTP provider version in its pyproject.toml without refreshing uv.lock. The constraints jobs run `uv sync`, which then tries to rewrite the lock file. The lock is bind-mounted as a single file in the container, so the rename fails with "Device or resource busy" and every "Generate constraints" job on v3-4-test fails.
This deprecates
airflow.utils.email. Its functions live inairflow.providers.smtp.utils.emailer(#74623), and the old names now forward to them with aDeprecatedImportWarning. Core now requiresapache-airflow-providers-smtp>=3.2.0, the first release with the emailer, so the floor change needs theallow provider dependency bumplabel.Existing imports and
email_backendsettings keep working. Keepemail_backendat its defaultairflow.utils.email.send_email_smtp: Airflow treats that value as "send withSmtpNotifier". Only the Python imports moved.What changes for code that calls these functions directly:
BaseHook.get_connection. Tasks and Airflow's server processes still find a Connection stored only in the metadata database. A standalone script outside Airflow's processes needs it from an environment variable or a secrets backend.airflow.configuration.conf.set()are not seen.airflow.cfgand environment variables work as before.airflow.utils.email.send_mime_emailno longer intercept the call made bysend_email_smtp, which now runs in the provider. Patchairflow.providers.smtp.utils.emailer.send_mime_emailinstead.These are also in the significant newsfragment and the deprecation warning.
Testing
from airflow.utils.email import *, the warning names the Connection lookup, and a server process finds a database-only Connection. They fail against the current module.3.2.0rc1installed, a real SMTP server (Mailpit) receives task retry and failure alerts for the default backend and for a custom backend that importsairflow.utils.email, and the messages match the original core code. The new tests also pass with SMTP 3.2.0.What's next
airflow.utils.email.[smtp]settings; after that release, core deprecates[smtp].airflow.utils.email.related: #30530, #74623
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 5.5) following the guidelines