#37261: AdminEmailHandler and BrokenLinkEmailsMiddleware raise on email transport
errors when MAILERS is configured
---------------------------------+----------------------------------------
Reporter: Adam Johnson | Owner: Adam Johnson
Type: Bug | Status: closed
Component: Core (Mail) | Version: 6.1
Severity: Release blocker | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+----------------------------------------
Comment (by Adam Johnson):
Replying to [comment:1 Mike Edmunds]:
There, I see:
> Django's two internal uses of fail_silently=True will be replaced with
MailerDoesNotExist checks. (See AdminEmailHandler and
BrokenLinkEmailsMiddleware earlier.)
But I don't see rationale about why not `try: ... except Exception: ...`
instead.
Replying to [comment:1 Mike Edmunds]:
> There's more discussion of the rationale behind this and several
alternatives we considered in the forum:
https://forum.djangoproject.com/t
/deprecating-or-changing-how-django-core-mail-handles-fail-
silently/44278/19 (and the lengthy series of preceding comments).
>
I read the thread, and it seems to cover `fail_silently` in general but
not these two specific use cases.
---
I understand that removing `fail_silently` was completely agreed-on, but I
think dropping its "continue on failure" behaviour in these two specific
cases was overreach. To me, `AdminEmailHandler` and
`BrokenLinkEmailsMiddleware` only send emails as a best-effort. The
failure to send an email should NOT crash the process/request:
* `AdminEmailHandler`: A process that tries to log to emails admins should
continue regardless of whether the email got through. Other logging
handlers are peppered with `try: ... except Exception: pass`. *All* of
Python’s built-in handler classes do this - see the `emit()` methods in
the `logging/handler.py` source, including
[
https://github.com/python/cpython/blob/87b120fdb58afd8f7cb79daa87122334e295b70c/Lib/logging/handlers.py#L1149-L1150
`SMTPHandler.emit()`]
* `BrokenLinkEmailsMiddleware`: A broken link should 404 regardless of
whether the email could be sent. Crashing and returning an error page is
unacceptable degradation when an email service provider is down, and could
cause search indexers to start treating a given page differently.
--
Ticket URL: <
https://code.djangoproject.com/ticket/37261#comment:2>