Skip to content

Improve the default SMTP task failure email template#67931

Open
wilmerdooley wants to merge 1 commit into
apache:mainfrom
wilmerdooley:oss/issue-61667
Open

Improve the default SMTP task failure email template#67931
wilmerdooley wants to merge 1 commit into
apache:mainfrom
wilmerdooley:oss/issue-61667

Conversation

@wilmerdooley

@wilmerdooley wilmerdooley commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Resolves #61667.

The default email that SmtpNotifier sends on task failure does not show which DAG or task failed, so it is hard to triage at a glance. This restyles the default templates for readability, keeping the change minimal and backward compatible.

What changed

  • templates/email.html: add DAG and Task rows (previously missing) alongside the existing Run ID, Try, State, Host and log link, and lay the body out as a scannable table. Layout uses a plain <table> with inline cell styles only (no <style> or <head> styling, no CSS grid or flexbox), so it renders consistently in Gmail and Outlook.
  • templates/email_subject.jinja2: a more scannable subject, [Airflow] {{ ti.dag_id }}.{{ ti.task_id }} {{ ti.state }} - Run {{ ti.run_id }}. The SLA branch is unchanged.
  • tests/unit/smtp/notifications/test_smtp.py: update the one assertion that pins the default subject.

Scope and compatibility

  • Only the SMTP provider default templates are touched. airflow-core and task-sdk are left alone, since email integration is moving out of core (PR [WIP] Migrate core EmailOperator to SMTP provider #30531).
  • Backward compatible: a user-provided subject_template or html_content_template (connection extras) still takes precedence over the bundled defaults.
Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Claude Code


Important

🛠️ Maintainer triage note for @wilmerdooley · by @potiuk · 2026-07-08 16:05 UTC

This PR was in the maintainer review queue, but its Sqlite and low-dependency provider tests are now failing — so I've removed the ready for maintainer review label and moved it back to your court.

The ball is in your court — you've been assigned. Fix the failing tests, then mark it Ready for review again. See the Pull Request quality criteria.

Automated triage — may be imperfect; a maintainer takes the next look.

Signed-off-by: wilmerdooley <wilmerdooley1@gmail.com>
@wilmerdooley wilmerdooley changed the title Improve default task failure email template for readability and operatio Improve the default SMTP task failure email template Jun 3, 2026
@eladkal

eladkal commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Can you please add before and after images if the template?

@potiuk potiuk added the ready for maintainer review Set after triaging when all criteria pass. label Jun 3, 2026
@wilmerdooley

wilmerdooley commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Before/after renders of the default task-failure email, with the same sample failure context in both:

Before (main):
before

After (this PR): adds DAG and Task rows and lays the fields out as a card with a header and a View Logs button.
after

@wilmerdooley

Copy link
Copy Markdown
Contributor Author

I looked into the two red checks and they aren't coming from this change. Both failed during the runner setup step ("Cleanup repo"), before the code was even checked out, when the runner tried to pull the bash:latest image and the Docker Hub pull timed out (exit 125). Because that setup step failed, the checkout and all the actual test steps were skipped rather than run, so the tests never executed in those two jobs. Everything else is green, including the smtp unit tests in the other matrix jobs.

A re-run of just those two jobs should clear them, but I can't trigger that myself as an external contributor. How would you prefer to proceed? Happy to rebase onto current main and push if a fresh commit is the easier way to re-trigger CI, though that's your call.

@potiuk potiuk removed the ready for maintainer review Set after triaging when all criteria pass. label Jul 8, 2026
@Vamsi-klu

Copy link
Copy Markdown
Contributor

The new layout is much easier to scan, but the bundled SmtpNotifier template is not limited to failure callbacks. Notifiers can also be attached to callbacks such as on_success_callback and on_retry_callback; whenever ti is present, this template currently renders the red Airflow Task Failed heading regardless of the actual task state.

Could you make that heading state-aware or neutral and add a regression test with a non-failure state? It would also be useful to assert the new Dag, task, state, and log-link fields directly, including that the log URL is the link target. The current default-template test sets TEST_TASK_STATE = None and only checks the subject and try count, so it does not protect most of the new behavior.

The two failing jobs are setup-only failures: both exhausted their stash-artifact download retries during Prepare breeze & CI image, before their test steps ran. A rebase and clean rerun are still needed, but those failures are not product-test failures. The before/after screenshots are already present, so no additional screenshot request is needed.


Drafted-by: Codex (GPT-5); reviewed by @Vamsi-klu before posting

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.

Improve default task failure email template for readability and operational clarity

4 participants