Kaydet (Commit) 4a246a02 authored tarafından Vinay Karanam's avatar Vinay Karanam Kaydeden (comit) Tim Graham

Refs #17235 -- Made MultiPartParser leave request.POST immutable.

üst 183f5015
...@@ -1785,7 +1785,7 @@ class ModelAdmin(BaseModelAdmin): ...@@ -1785,7 +1785,7 @@ class ModelAdmin(BaseModelAdmin):
} }
if request.method == 'POST': if request.method == 'POST':
formset_params.update({ formset_params.update({
'data': request.POST, 'data': request.POST.copy(),
'files': request.FILES, 'files': request.FILES,
'save_as_new': '_saveasnew' in request.POST 'save_as_new': '_saveasnew' in request.POST
}) })
......
...@@ -205,6 +205,7 @@ class UserAdmin(admin.ModelAdmin): ...@@ -205,6 +205,7 @@ class UserAdmin(admin.ModelAdmin):
# * The user has pressed the 'Save and add another' button # * The user has pressed the 'Save and add another' button
# * We are adding a user in a popup # * We are adding a user in a popup
if '_addanother' not in request.POST and IS_POPUP_VAR not in request.POST: if '_addanother' not in request.POST and IS_POPUP_VAR not in request.POST:
request.POST = request.POST.copy()
request.POST['_continue'] = 1 request.POST['_continue'] = 1
return super(UserAdmin, self).response_add(request, obj, return super(UserAdmin, self).response_add(request, obj,
post_url_continue) post_url_continue)
...@@ -289,6 +289,7 @@ class MultiPartParser(object): ...@@ -289,6 +289,7 @@ class MultiPartParser(object):
if retval: if retval:
break break
self._post._mutable = False
return self._post, self._files return self._post, self._files
def handle_file_complete(self, old_field_name, counters): def handle_file_complete(self, old_field_name, counters):
......
...@@ -634,6 +634,10 @@ Miscellaneous ...@@ -634,6 +634,10 @@ Miscellaneous
* The undocumented ``django.utils.functional.lazy_property`` is removed. * The undocumented ``django.utils.functional.lazy_property`` is removed.
* For consistency with non-multipart requests, ``MultiPartParser.parse()`` now
leaves ``request.POST`` immutable. If you're modifying that ``QueryDict``,
you must now first copy it, e.g. ``request.POST.copy()``.
.. _deprecated-features-1.11: .. _deprecated-features-1.11:
Features deprecated in 1.11 Features deprecated in 1.11
......
...@@ -533,6 +533,25 @@ class RequestsTests(SimpleTestCase): ...@@ -533,6 +533,25 @@ class RequestsTests(SimpleTestCase):
self.assertEqual(request.read(13), b'--boundary\r\nC') self.assertEqual(request.read(13), b'--boundary\r\nC')
self.assertEqual(request.POST, {'name': ['value']}) self.assertEqual(request.POST, {'name': ['value']})
def test_POST_immutable_for_mutipart(self):
"""
MultiPartParser.parse() leaves request.POST immutable.
"""
payload = FakePayload("\r\n".join([
'--boundary',
'Content-Disposition: form-data; name="name"',
'',
'value',
'--boundary--',
]))
request = WSGIRequest({
'REQUEST_METHOD': 'POST',
'CONTENT_TYPE': 'multipart/form-data; boundary=boundary',
'CONTENT_LENGTH': len(payload),
'wsgi.input': payload,
})
self.assertFalse(request.POST._mutable)
def test_POST_connection_error(self): def test_POST_connection_error(self):
""" """
If wsgi.input.read() raises an exception while trying to read() the If wsgi.input.read() raises an exception while trying to read() the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment