Skip to content

Restore pluggable email backend for task failure/retry alerts#69877

Draft
potiuk wants to merge 1 commit into
apache:mainfrom
potiuk:restore-pluggable-email-backend
Draft

Restore pluggable email backend for task failure/retry alerts#69877
potiuk wants to merge 1 commit into
apache:mainfrom
potiuk:restore-pluggable-email-backend

Conversation

@potiuk

@potiuk potiuk commented Jul 14, 2026

Copy link
Copy Markdown
Member

What

Restore the ability to deliver email_on_failure / email_on_retry task alerts through a pluggable backend (SES, SendGrid, or any custom notifier), which regressed in #57354.

Why

email_on_failure / email_on_retry are deprecated (slated for Airflow 4, migrate to SmtpNotifier) but still functional. Since #57354, task failure/retry emails are routed unconditionally through SmtpNotifier, silently ignoring the [email] email_backend configuration. Deployments using a custom email_backend (Amazon SES, SendGrid, org-internal) stopped receiving failure/retry alerts even though the config option still exists and the deprecated params still work. This restores that behaviour while keeping the single-notifier design #57354 introduced.

How

_send_error_email_notification (shared by both the worker task-runner path and the DAG-processor callback path) now resolves the notifier by precedence:

  1. [email] email_notifier (new option, default SmtpNotifier) — any BaseNotifier whose constructor accepts to / from_email / subject / html_content.
  2. Legacy [email] email_backend (non-default) — transparently wrapped in a new LegacyEmailBackendNotifier (added to apache-airflow-providers-common-compat) so existing SES/SendGrid setups keep working unchanged. The backend is loaded lazily from config at notify time, so the Task SDK keeps no static dependency on airflow.utils.email.
  3. Otherwise the default SmtpNotifier.

Because both failure-email entry points funnel through the same function, the selected backend is used consistently regardless of how the task failed (normal failure vs. zombie/killed).

Tests

  • TestEmailNotifications (task-sdk): default still uses SmtpNotifier (unchanged regression tests), custom email_notifier selected, legacy email_backend wrapped and invoked, explicit email_notifier overrides legacy backend, unresolvable notifier logged (no raise).
  • TestExecuteEmailCallbacks (DAG-processor path): unchanged and green — confirms both entry points stay consistent.
  • test_notifier.py (common.compat): unit tests for LegacyEmailBackendNotifier dispatch.

Notes

  • The deprecated email_on_* params are not un-deprecated; this only keeps their existing behaviour pluggable until removal in Airflow 4.
  • No newsfragment yet — will add {PR_NUMBER}.improvement.rst once this PR number is known.

Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 4.8)

Generated-by: Claude Code (Opus 4.8) following the guidelines

Since apache#57354, task email_on_failure / email_on_retry alerts were routed
unconditionally through SmtpNotifier, silently ignoring the
[email] email_backend configuration. Custom backends (SES, SendGrid,
org-internal) stopped delivering failure/retry emails even though the
deprecated email_on_* parameters still worked.

This restores pluggability while keeping the single-notifier design that
apache#57354 introduced:

- New [email] email_notifier option selects the BaseNotifier used for
  failure/retry alerts (default: SmtpNotifier). Any BaseNotifier whose
  constructor accepts to / from_email / subject / html_content can be used.
- A legacy [email] email_backend (non-default) is transparently wrapped in
  a new LegacyEmailBackendNotifier adapter in common.compat, so existing
  SES/SendGrid/custom email_backend setups keep working without change.
- Both the worker task-runner path and the DAG-processor callback path
  resolve the notifier through the same _send_error_email_notification
  function, so the selected backend is used consistently regardless of how
  the task failed.

The adapter loads the backend lazily from config at notify time, keeping
the Task SDK free of a static dependency on airflow.utils.email.

Adds LegacyEmailBackendNotifier to apache-airflow-providers-common-compat.
Comment on lines +2397 to +2409
email_notifier:
description: |
Dotted path to the notifier class used to deliver ``email_on_failure`` and
``email_on_retry`` task alerts. The class must be a ``BaseNotifier`` subclass whose
constructor accepts ``to``, ``from_email``, ``subject`` and ``html_content`` keyword
arguments. Override it to route failure/retry alerts through a backend other than SMTP
(for example an SES- or SendGrid-based notifier). Both the worker task-runner path and
the DAG-processor callback path load the notifier from this single option, so the
selected backend is used consistently regardless of how the task failed.
version_added: 3.3.1
type: string
example: ~
default: "airflow.providers.smtp.notifications.smtp.SmtpNotifier"

@eladkal eladkal Jul 14, 2026

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.

We want all email related settings out of core
#30531

[DISCUSS] Drop email integration from Airflow Core
the community disagreed with me about removing all of that as part of Airflow 3. That ship has sailed but I think we should avoid adding more oil to this fire. We need to complete the Core->SMTP migration and deprecate all email related stuff from core.

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.

2 participants