Django Rest Framework - электронная почта администратора имеет пустые трассировки

Получение пустой трассировки стека из писем администратора для 500 ошибок в Django Rest Framework (DRF):

Exception Location:     , line , in 

Из исходного кода DRF я вижу:

{% if lastframe %}
<tr>
  <th>Exception Location:</th>
  <td><span class="fname">{{ lastframe.filename }}</span>, line {{ lastframe.lineno }}, in {{ lastframe.function }}</td>
</tr>{% endif %}

Значит, это должно быть как-то связано с нашим пользовательским обработчиком исключений, в котором мы формируем данные ответа JSON, чтобы они соответствовали унаследованной системе?

def custom_exception_handler(exc, context):
"""
https://github.com/HackSoftware/Django-Styleguide#errors--exception-handling
Format the error before passing to CustomJSONRenderer
"""
if isinstance(exc, DjangoValidationError):
    exc = exceptions.ValidationError(as_serializer_error(exc))

if isinstance(exc, Http404):
    exc = exceptions.NotFound()

if isinstance(exc, PermissionDenied):
    exc = exceptions.PermissionDenied()

# Call REST framework's default exception handler first,
# to get the standard error response.
response = exception_handler(exc, context)

# Unknown error occured!
if response is None:
    if exc:
        response.data = {
            "error": {
                "client_message": "Whoops, something went wrong",
                "developer_message": "".join(
                    traceback.TracebackException.from_exception(exc).format()
                ),
                # "developer_message": str(exc),
            }
        }
        response.status_code = 500
        return response
    response.data = {
        "error": {
            "client_message": "Whoops, something went awry",
            "developer_message": "unknown exception handling error - response is None",
        }
    }
    response.status_code = 500
    return response  

errors = []
message = response.data.get("detail")
if not message:
    for field, value in response.data.items():
        errors.append(f"{field} : {' '.join(value)}")

    response.data["errors"] = {
        "developer_message": " ".join(errors),
        "client_message": "Whoops, something went wrong",
    }
else:
    response.data["errors"] = {
        "developer_message": str(message),
        "client_message": "Whoops, something went wrong",
    }

return response

Я могу видеть lastframe в моих журналах как отсутствующую информацию:

'lastframe': {'exc_cause': None, 'exc_cause_explicit': True, 'tb': None, 'type': 'user'}

Может ли кто-нибудь понять, почему lastframe будет отсутствовать информация о трассировке, которую я ищу?

Вернуться на верх