From 585b1b0707455c05b92523f2b4f1e57a8e56c089 Mon Sep 17 00:00:00 2001 From: Michael Bunsen Date: Mon, 29 Jun 2026 12:37:10 -0700 Subject: [PATCH 1/2] fix: stop admin emails on every HTTP 500 in production Django's DEFAULT_LOGGING routes the "django" logger to AdminEmailHandler ("mail_admins"), which sends a synchronous outbound email for each HTTP 500. Override it to console-only so the AdminEmailHandler is bypassed. Sentry already captures all ERROR-level records independently via LoggingIntegration, so no observability is lost. Co-Authored-By: Claude Opus 4.8 (1M context) --- config/settings/production.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/config/settings/production.py b/config/settings/production.py index e4abdf44e..60ad36d6b 100644 --- a/config/settings/production.py +++ b/config/settings/production.py @@ -177,6 +177,17 @@ }, } +# Django's default mail_admins handler sends email synchronously, blocking a worker +# thread per HTTP 500; other (async/queued) handlers are recommended. Disabled by +# default and gated behind an env var; errors are already captured by Sentry. +ADMIN_ERROR_EMAILS = env.bool("DJANGO_ADMIN_ERROR_EMAILS", default=False) +if not ADMIN_ERROR_EMAILS: + LOGGING["loggers"]["django"] = { + "level": "INFO", + "handlers": ["console"], + "propagate": False, + } + # Sentry # ------------------------------------------------------------------------------ SENTRY_DSN = env("SENTRY_DSN") From 8ccbc17f49ffb852e9ba7a79df5025595a53060a Mon Sep 17 00:00:00 2001 From: Michael Bunsen Date: Wed, 22 Jul 2026 20:18:40 -0700 Subject: [PATCH 2/2] fix: make the admin-emails-on path an explicit branch When DJANGO_ADMIN_ERROR_EMAILS=True the mail_admins handler comes from Django's DEFAULT_LOGGING, not this file. An explicit else branch makes that visible at the site of the toggle instead of hidden in Django's defaults. Co-Authored-By: Claude --- config/settings/production.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config/settings/production.py b/config/settings/production.py index 60ad36d6b..a4a671f20 100644 --- a/config/settings/production.py +++ b/config/settings/production.py @@ -187,6 +187,11 @@ "handlers": ["console"], "propagate": False, } +else: + # Nothing to wire here: Django's DEFAULT_LOGGING attaches the mail_admins handler + # to the "django" logger before this module's LOGGING is applied. Explicit branch + # so the "on" path is visible here instead of hidden in Django's defaults. See #1356. + pass # Sentry # ------------------------------------------------------------------------------