Search code examples
pythondjangodjango-email

Request repr() unavailable in Django 500 error email: how do I debug how to get the full stack trace?


Normally the django 'mail_admins' logging handler will email you 500 errors to ADMINS along with a useful stacktrace of what happened.

But for some reason I'm getting error emails with

Request repr() unavailable

at the bottom of the email! Anyone know how to figure out why this is happening? (So I can get stacktraces to fix bugs with!)


Solution

  • Although it is a question long time ago, the answer here might help others in the future. It's important to pass in request through extra.

    logger = logging.getLogger(__name__)
    logger.error(
        logging.traceback.format_exc(),
        extra={
            'status_code': 500, # or else
            'request': request
        }
    )