Skip to content

Instantly share code, notes, and snippets.

@eprikazc
Created August 18, 2017 12:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eprikazc/32bf9f182d030985cbca80c75aaf6589 to your computer and use it in GitHub Desktop.
Save eprikazc/32bf9f182d030985cbca80c75aaf6589 to your computer and use it in GitHub Desktop.
Middleware to work around Sentry-DRF compatibility issue
class RequestBodyMiddleware(object):
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
"""
Access request.body before request.
We need it for request.body to still be accessible after request
for example while handling exceptions in Sentry
See https://github.com/encode/django-rest-framework/issues/4050
"""
_ = request.body
response = self.get_response(request)
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment