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

RawPostDataException with 0.6.8 #67

Open
dmodin opened this issue May 2, 2019 · 15 comments
Open

RawPostDataException with 0.6.8 #67

dmodin opened this issue May 2, 2019 · 15 comments

Comments

@dmodin
Copy link

dmodin commented May 2, 2019

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

@tclancy
Copy link
Contributor

tclancy commented May 2, 2019

Is this happening on all requests or just some? It feels like this may be a setup issue.

@oneandonlyonebutyou
Copy link

I got this error too, the moment I used https://github.com/miki725/django-url-filter

Based on an old post I added :
REST_FRAMEWORK = {
"FORM_METHOD_OVERRIDE": None,
"FORM_CONTENT_OVERRIDE": None,
"FORM_CONTENTTYPE_OVERRIDE": None,
...}

Could you please investigate this Thanks.

@tclancy
Copy link
Contributor

tclancy commented May 2, 2019

Can one of you provide a test case that causes the issue? Guessing something in #65 is causing the body to be read and we don't have a test covering the problem.

@tclancy
Copy link
Contributor

tclancy commented May 2, 2019

@kennethjiang can you guys take a look at this to see if the last PR caused an error?

@dmodin
Copy link
Author

dmodin commented May 2, 2019 via email

@dmodin
Copy link
Author

dmodin commented May 3, 2019

Can't reproduce it easily in a clean project but I think the issue is when posting data including uploaded file

therefromhere added a commit to therefromhere/django_request_logging_bug that referenced this issue May 5, 2019
@therefromhere
Copy link
Contributor

therefromhere commented May 5, 2019

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'...

@fotometabata
Copy link

fotometabata commented May 21, 2019

thank you.
Resolved after downgrade the "django-request-logging" version from 0.6.9 to 0.6.7

It seems that the version was upgraded because no version was specified in the "requirements.txt".

But, I did not understand the cause that would occur when 0.6.9. sorry.

@palmchou
Copy link

Same exact issue. Attached trace stack below.

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.6/site-packages/request_logging/middleware.py", line 99, in __call__
    self.process_body(request)
  File "/usr/local/lib/python3.6/site-packages/request_logging/middleware.py", line 166, in process_body
    if not request.body:
  File "/usr/local/lib/python3.6/site-packages/django/http/request.py", line 275, 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

In my case, the request is a POST as multipart/form with a file upload.

@kennethjiang
Copy link
Contributor

@kennethjiang can you guys take a look at this to see if the last PR caused an error?

Sorry for missing your question @tclancy . We can't reproduce this problem here.

@therefromhere
Copy link
Contributor

@kennethjiang did you try using the example project I linked above?

I think the bug is triggered by a POST that contains no form fields (eg of file only).

@wwsean08
Copy link
Contributor

Working on this now and figuring out how to fix it

@wwsean08 wwsean08 mentioned this issue May 23, 2019
@krzysieqq
Copy link

Still in 0.7.1

@JocelynDelalande
Copy link

From my tests : I had the bug in 0.6.9, upgrading to 0.7.2 fixed it.

@krzysieqq
Copy link

krzysieqq commented Sep 16, 2021

Still in 0.7.3, problem doesn't exists in 0.7.2

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

10 participants