Alexander Ljungberg  committed 87c9a20

Fixed: if for a PUT operation some middleware accessed request.POST, the coerce_put_post fix for Django's lack of PUT support would cause an exception. This fix resets the request so that coerce can work its magic.

  • Participants
  • Parent commits 7970b07
  • Branches default

Comments (0)

Files changed (1)

File piston/

     in mod_python. This should fix it.
     if request.method == "PUT":
+        # Bug fix: if _load_post_and_files has already been called, for
+        # example by middleware accessing request.POST, the below code to
+        # pretend the request is a POST instead of a PUT will be too late
+        # to make a difference. Also calling _load_post_and_files will result 
+        # in the following exception:
+        #   AttributeError: You cannot set the upload handlers after the upload has been processed.
+        # The fix is to check for the presence of the _post field which is set 
+        # the first time _load_post_and_files is called (both by and 
+        # If it's set, the request has to be 'reset' to redo
+        # the query value parsing in POST mode.
+        if hasattr(request, '_post'):
+            del request._post
+            del request._files
             request.method = "POST"