django-extensions: Runserver_plus exceptions stacktrace is polluted

Hi there,

When an uncaught exception occurs in my apps using runserver_plus, the stacktrace is going through a significant amount of redundant code, and I can’t figure out why. 10 calls are made to six.reraise(exc_type, exc_value, tb). I think it should probably be improved for clarity.

Using Django 1.11 / Python 2.7 / Django Extensions last table (2.0.7).

127.0.0.1 - - [30/Apr/2018 14:55:01] "GET /crash/ HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
    return self.application(environ, start_response)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 157, in __call__
    response = self.get_response(request)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 124, in get_response
    response = self._middleware_chain(request)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 43, in inner
    response = response_for_exception(request, exc)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 93, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 139, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/utils/deprecation.py", line 140, in __call__
    response = self.get_response(request)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 43, in inner
    response = response_for_exception(request, exc)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 93, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 139, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/utils/deprecation.py", line 140, in __call__
    response = self.get_response(request)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 43, in inner
    response = response_for_exception(request, exc)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 93, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 139, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/utils/deprecation.py", line 140, in __call__
    response = self.get_response(request)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 43, in inner
    response = response_for_exception(request, exc)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 93, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 139, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/utils/deprecation.py", line 140, in __call__
    response = self.get_response(request)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 43, in inner
    response = response_for_exception(request, exc)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 93, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 139, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/utils/deprecation.py", line 140, in __call__
    response = self.get_response(request)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 43, in inner
    response = response_for_exception(request, exc)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 93, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 139, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/utils/deprecation.py", line 140, in __call__
    response = self.get_response(request)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 43, in inner
    response = response_for_exception(request, exc)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 93, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 139, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/utils/deprecation.py", line 140, in __call__
    response = self.get_response(request)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 43, in inner
    response = response_for_exception(request, exc)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 93, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 139, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/Users/antwan/Projects/myproject/apps/core/middleware.py", line 14, in __call__
    return self.get_response(request)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 43, in inner
    response = response_for_exception(request, exc)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 93, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 139, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/utils/deprecation.py", line 140, in __call__
    response = self.get_response(request)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 43, in inner
    response = response_for_exception(request, exc)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 93, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 139, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/Users/antwan/Projects/myproject/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/antwan/Projects/myproject/apps/core/views.py", line 506, in crash_view
    raise Exception('A test exception occured!')

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

I took another look today and changed my mind, null_technical_500_response will need to be modified to clean up the stacktrace. Django calls django_extensions’s null_technical_500_response for each Middleware Mixin object in a stack (because it is overridden in runserver_plus.py). By the time an uncaught exception occurs in the django app there are typically 8-10 of these Mixins in the stack, hence all the six reraise calls on top of the original exception.

I don’t think this is related to python 3’s exception chaining as mentioned here. I think null_technical_500_response needs to be modified to return django_extensions’s version of a response to be displayed, instead of raising an exception. Not sure how to do this yet, but should be able to figure it out next time I can look in a few days.

@antwan @trbs Would you be open to me creating a bounty for this issue on Gitcoin ?

yay! paying out now @jhselvik

/a wild gitcoin funder appears

since this is a problem i currently have, and i have no idea how to solve nor do i have the time to really look into it. im going to put a small $75 bounty on it. to whomever figures out the issue, let me know if it’s more complex than a $75 bounty would cover ( i just dont know the complexity from the outside)

No problem. If that works out we might be able to do it for other issues as well 😃