DRF 3.6.4/3.7.0 breaks reading request.POST if request.body was read · Issue #5582 · encode/django-rest-framework (original) (raw)

Checklist

Steps to reproduce

Expected behavior

Actual behavior


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.


edited for formatting (@rpkilby)