question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make sure everything works with Django-Rest-Framework

See original GitHub issue

We should django-rest-framework’s request.data instead of trying to extract a structured body ourselves

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
cwmoo740commented, Jan 9, 2019

It’s somewhat difficult to understand why using sentry with django_rest_framework does not upload request bodies out of the box. There were a few scattered SO and github threads about the problem but the few that I found refer to the older sentry client. I managed to track down the problem and wanted to share my results.

  1. DRF uses its own json parser and calls request.read directly, without storing the result on django’s request._body
  2. Sentry attempts to read from django’s request.body, which then errors because the stream has already been read and not assigned to request._body

Here are relevant parts of the code that I found:

https://github.com/encode/django-rest-framework/blob/3.9.0/rest_framework/parsers.py#L68

https://github.com/django/django/blob/2.1.5/django/http/request.py#L283

One workaround is to do something silly like this:

@api_view(['POST'])
def my_view(request):
    request.body # side effect of storing the whole request body in memory on request._request._body
    do_something(request.data)

I put up a repo demonstrating this.

https://github.com/cwmoo740/django_sentry_debugging

It would be significantly better imo if there was a separate integration for DjangoRestFramework that simply read from request.data directly and let DRF do the parsing, as you suggested when you opened this thread.

If that work will be accepted I can tackle it and put up a pr.

0reactions
untitakercommented, Apr 5, 2019

0.7.10 was released which should fix this

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django REST framework: Home
Django REST framework is a powerful and flexible toolkit for building Web APIs. ... Don't forget to make sure you've also added rest_framework...
Read more >
10 things you need to know to effectively use Django Rest ...
In this article I want to share some ideas and tricks that I got to know while working with Django Rest Framework in...
Read more >
Django Rest Framework – An Introduction - Real Python
Make sure both GET and POST requests are working correctly. Delete. Before changing or adding anything, test it out. Try the delete link....
Read more >
Build a Django REST API with the Django Rest Framework ...
Build a Django Rest API with the Django Rest Framework. Complete Tutorial. There's a lot to cover so be sure to checkout the...
Read more >
Django REST Framework Course – Build Web APIs with Python
Django REST Framework is a powerful and flexible toolkit for building Web APIs. In this course for beginner you will learn how to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found