django-request-logging: RawPostDataException with 0.6.8

We see this error when doing a post after upgrading from 0.6.7 to 0.6.8:

/request_logging/middleware.py:166: in process_body
@property
    def body(self):
        if not hasattr(self, '_body'):
            if self._read_started:
>               raise RawPostDataException("You cannot access body after reading from request's data stream")
E               django.http.request.RawPostDataException: You cannot access body after reading from request's data stream

using django 2.2.1

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 15 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I’ve managed to reproduce the bug - see example project here: https://github.com/therefromhere/django_request_logging_bug

I think the django-request-logging tests need a bit of refactoring so they can accommodate an integration test like this?

Using the example project:

with Django==2.2.1 django-request-logging==0.6.9

./manage.py test
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
E
======================================================================
ERROR: test_bug (django_request_logging_bug.apps.bug.tests.MyTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/johnc/Projects/django_request_logging_bug/django_request_logging_bug/apps/bug/tests.py", line 8, in test_bug
    self.client.post("/bug/create/")
  File "/home/johnc/.virtualenvs/scratch_django_22/lib/python3.7/site-packages/django/test/client.py", line 543, in post
    response = super().post(path, data=data, content_type=content_type, secure=secure, **extra)
  File "/home/johnc/.virtualenvs/scratch_django_22/lib/python3.7/site-packages/django/test/client.py", line 357, in post
    secure=secure, **extra)
  File "/home/johnc/.virtualenvs/scratch_django_22/lib/python3.7/site-packages/django/test/client.py", line 422, in generic
    return self.request(**r)
  File "/home/johnc/.virtualenvs/scratch_django_22/lib/python3.7/site-packages/django/test/client.py", line 503, in request
    raise exc_value
  File "/home/johnc/.virtualenvs/scratch_django_22/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/johnc/.virtualenvs/scratch_django_22/lib/python3.7/site-packages/request_logging/middleware.py", line 99, in __call__
    self.process_body(request)
  File "/home/johnc/.virtualenvs/scratch_django_22/lib/python3.7/site-packages/request_logging/middleware.py", line 166, in process_body
    if not request.body:
  File "/home/johnc/.virtualenvs/scratch_django_22/lib/python3.7/site-packages/django/http/request.py", line 280, in body
    raise RawPostDataException("You cannot access body after reading from request's data stream")
django.http.request.RawPostDataException: You cannot access body after reading from request's data stream

----------------------------------------------------------------------
Ran 1 test in 0.021s

FAILED (errors=1)
Destroying test database for alias 'default'...