You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DRF 3.6.4/3.7.0 breaks reading request.POST if request.body was read #5582
I have reduced the issue to the simplest possible case.
I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)
Steps to reproduce
Create any DRF view
Add a middleware or a signal handler that uses request.POST
Expected behavior
request.POST works fine
Actual behavior
AttributeError is raised by Django's HttpRequest._load_post_or_files
The reason the exception is raised is because Django's WSGIReqeust.POST checks if hasattr(self, '_post') (which it doesn't have) and proceeds to _load_post_and_data, which in turn calls parse_file_upload which tries to set self.upload_handlers, but the upload_handler.setter checks if hasattr(self, '_files'). At this point, _files has already been set by DRF (to make closing file handles possible), so it raises an exception.
I think the solution to this is to set request._post in addition to request._files to preserve the interface. I am not sure if there's an easy way to set it to the original POST as it seems DRF only calls _load_data_and_files, which deserializes the data etc.
changed the title [-]DRF 3.6.4/3.7.3 breaks reading request.POST directly[/-][+]DRF 3.6.4/3.7.0 breaks reading request.POST if request.body was read[/+]on Nov 9, 2017
@xordoquy No. I bumped into it today, while trying to update my project's dependencies, including updating DRF from 3.6.3 to 3.6.4 (can't go to 3.7 yet). It has worked fine before that.
Activity
rpkilby commentedon Nov 9, 2017
For context, this was changed in #5262, which superseded #5255. Amusingly enough, the original PR did set
_postin addition to_files.@D3X - would you be able to reduce this into a failing test case?
D3X commentedon Nov 9, 2017
@rpkilby Thanks for the prompt response. I'll try to submit a PR later tonight.
(Misclicked on the mobile version and closed the ticket by mistake)
[-]DRF 3.6.4/3.7.3 breaks reading request.POST directly[/-][+]DRF 3.6.4/3.7.0 breaks reading request.POST if request.body was read[/+]Added a failing test for encode#5582
D3X commentedon Nov 9, 2017
@rpkilby I played with it a bit and it seems it only breaks if
request.bodywas read before DRF did its magic.Also have added a failing test PR, as you can see above.
xordoquy commentedon Nov 9, 2017
This doesn't look very new to me. Did you had that issue in prior versions ?
D3X commentedon Nov 9, 2017
@xordoquy No. I bumped into it today, while trying to update my project's dependencies, including updating DRF from 3.6.3 to 3.6.4 (can't go to 3.7 yet). It has worked fine before that.
Added a failing test for encode#5582
Added a failing test for encode#5582
Added a failing test for encode#5582
Fix request body/POST access (#5590)
Fix request body/POST access (encode#5590)