potiuk opened a new pull request, #69877:
URL: https://github.com/apache/airflow/pull/69877

   ## 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?
   
   - [X] Yes — Claude Code (Opus 4.8)
   
   Generated-by: Claude Code (Opus 4.8) following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   


-- 
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