Opened 3 years ago

Closed 3 years ago

#31424 closed Bug (invalid)

django.utils.log.AdminEmailHandler won't include stack trace when django.server logs are propogated

Reported by: Wesley Ellis Owned by: nobody
Component: Uncategorized Version: 3.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


If I configure LOGGING such that logger has the propagate property set to True, the AdminEmail handler no longer contains a stack trace.

I can reproduce with the following changes to for a brand new django app here:

EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

ADMINS = [('Test', '')]

    "version": 1,
    "disable_existing_loggers": False,
    "handlers": {
        "console": {
            "level": "INFO",
            "class": "logging.StreamHandler",
        "mail_admins": {
            "level": "ERROR",
            "class": "django.utils.log.AdminEmailHandler",
    "loggers": {
        "django": {"handlers": ["console", "mail_admins"], "level": "INFO",},
        "django.server": {
            "handlers": ["console"],
            "level": "INFO",
            "propagate": True, # If this is True, AdminEmailHandler gets a record where record.request is a socket

The stack trace seems to be coming from the technical_500 templates, but those templates don't include the stack frame if there is no request:

The request is set here:

But for some reason I don't understand, record.request is a socket object when propagate: True

I've attached the logs for both cases here:

Change History (1)

comment:1 Changed 3 years ago by Carlton Gibson

Resolution: invalid
Status: newclosed

Hi Wesley.

The django.server logger applies to the WSGI server infrastructure that powers the development runserver command. This is essentially a socket server, so when that logger adds self.request to the log record, it is adding the socket, not a Django request object that you're expecting. (I'm guessing this is why django.server does not propagate by default.) When propagating up to the django logger, and hitting the mail_admins handler, it's that that's logged.

The properly formatted report that is generated is coming from the django.request logger, which is used inside the request handling machinery (django/core/handlers) and which gets the, expected, Django request object.

Note: See TracTickets for help on using tickets.
Back to Top