Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions config/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Comment on lines +185 to +189
Comment on lines +184 to +189

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The else (on) branch is implicit today: DJANGO_ADMIN_ERROR_EMAILS=True just falls through and inherits Django's DEFAULT_LOGGING mail_admins handler. That works, but it depends on Django internals and isn't visible at this line. Minimal fix — make the on-path explicit:

Suggested change
if not ADMIN_ERROR_EMAILS:
LOGGING["loggers"]["django"] = {
"level": "INFO",
"handlers": ["console"],
"propagate": False,
}
if not ADMIN_ERROR_EMAILS:
LOGGING["loggers"]["django"] = {
"level": "INFO",
"handlers": ["console"],
"propagate": False,
}
else:
# Admin error emails are on. Nothing here wires them: they come from Django's
# DEFAULT_LOGGING, which attaches the mail_admins handler to the "django" logger
# before this module's LOGGING is applied. Kept as an explicit branch so the
# "on" behaviour is visible at this line rather than hidden in Django's defaults.
pass

If you'd rather not depend on Django's defaults at all, the more robust version defines the mail_admins handler and the django logger explicitly in the else branch, so the on behaviour is fully self-contained in this file. Happy to draft that instead — this minimal version matches the intent without expanding scope.


# Sentry
# ------------------------------------------------------------------------------
SENTRY_DSN = env("SENTRY_DSN")
Expand Down
Loading