Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exceptions stack trace are truncated since 3.9.3 #6655

Closed
antwan opened this issue May 8, 2019 · 12 comments
Closed

Exceptions stack trace are truncated since 3.9.3 #6655

antwan opened this issue May 8, 2019 · 12 comments
Milestone

Comments

@antwan
Copy link

antwan commented May 8, 2019

Since introduction of change #6435 (commit fd32dd7), exceptions that are raised within a DRF APIView have their stack trace truncated. It is therefore very difficult to fix issues as there is no longer indication of line number/file affected when exception is uncaught.

Steps to reproduce

  1. Create a simple view in your code to trigger an uncaught exception
# views.py
from rest_framework.views import APIView

class CrashView(APIView):
    def get(self, request):
        raise Exception('A test exception occured!')
# urls.py
from django.conf.urls import url
from .views import CrashView

urlpatterns = [
    url(r'^crash-me/$', CrashView.as_view(), name='crash-me'),
]
  1. Call the view
    GET /crash-me/

Expected behavior

Stack trace returned should be the following:

Traceback (most recent call last):
  File "/Users/antwan/Projects/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/Users/antwan/Projects/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/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/venv/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/Users/antwan/Projects/venv/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/Users/antwan/Projects/venv/lib/python2.7/site-packages/rest_framework/views.py", line 495, in dispatch
    response = self.handle_exception(exc)
  File "/Users/antwan/Projects/venv/lib/python2.7/site-packages/rest_framework/views.py", line 455, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/Users/antwan/Projects/venv/lib/python2.7/site-packages/rest_framework/views.py", line 492, in dispatch
    response = handler(request, *args, **kwargs)
  File "/Users/antwan/Projects/drf-bug/views.py", line 5, in get
    raise Exception('A test exception occured!')

Actual behavior

Stack trace returned is the following:

Traceback (most recent call last):
  File "/Users/antwan/Projects/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/Users/antwan/Projects/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/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/venv/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/Users/antwan/Projects/venv/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/Users/antwan/Projects/venv/lib/python2.7/site-packages/rest_framework/views.py", line 495, in dispatch
    response = self.handle_exception(exc)
  File "/Users/antwan/Projects/venv/lib/python2.7/site-packages/rest_framework/views.py", line 455, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/Users/antwan/Projects/venv/lib/python2.7/site-packages/rest_framework/views.py", line 466, in raise_uncaught_exception
    raise exc
@rpkilby
Copy link
Member

rpkilby commented May 8, 2019

Interesting. From my test in #6435 (comment), there didn't seem to be a significant behavior change. Are you using Python 2 or Python 3?

@rpkilby
Copy link
Member

rpkilby commented May 8, 2019

Agh. Confirmed. The change is fine on Python 3, but negatively affects Python 2 error handling.

@antwan
Copy link
Author

antwan commented May 9, 2019

ref #6404
Although, knowing my luck, this will break something.

Bingo 😬

@rpkilby
Copy link
Member

rpkilby commented May 9, 2019

Can you roll back to 3.9.2? iirc, the only meaningful change was #6613 - the rest being docs/test fixes. Diff from 3.9.2...3.9.3

Also, at this point, we're already in the process of rolling 3.10, which drops Python 2 support entirely.

@antwan
Copy link
Author

antwan commented May 10, 2019

Of course I've rolled back to 3.9.2, but that's definitely not an answer.

I don't see why we should leave a version on prod with rather serious bugs IMO. This should be fixed for the the time being (ie as long as 3.9 series is supported). I'm certainly not the only one affected here.
All the more #6404 does not bring a lot TBH.

@xordoquy
Copy link
Collaborator

I don't consider this issue as serious although it definitively is really annoying.
As said, Python 2 has already been dropped so it's quite some extra work to issue a 3.9.4.
We need to see whether the best option is to deactivate 3.9.3 from pypi or to issue another release.

@rpkilby
Copy link
Member

rpkilby commented May 10, 2019

It shouldn't be too difficult. At least, not much more extra work than just the release itself.

  • create a 3.9.x branch
  • rollback the fix
  • create new release

The question is whether or not @carltongibson has the bandwidth to run through this. I don't want to volunteer/obligate him to work if he doesn't have the time.

@carltongibson
Copy link
Collaborator

If you can create the tag Ryan I am happy to push it to PyPI

@rpkilby
Copy link
Member

rpkilby commented May 10, 2019

👌

@rpkilby rpkilby added this to the 3.9.4 milestone May 10, 2019
@rpkilby
Copy link
Member

rpkilby commented May 10, 2019

@carltongibson 3.9.4 is up 3.9.3...3.9.4

@rpkilby rpkilby closed this as completed May 10, 2019
@rpkilby
Copy link
Member

rpkilby commented May 10, 2019

Also, there is a 3.9.x brach if we need to make any additional maintenance updates.

@carltongibson
Copy link
Collaborator

OK. Super I’ll push that now. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants