1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

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

This commit is contained in:
Vinay Karanam 2016-11-16 18:52:38 +05:30 committed by Tim Graham
parent 183f501540
commit 4a246a02bd
5 changed files with 26 additions and 1 deletions

View File

@ -1785,7 +1785,7 @@ class ModelAdmin(BaseModelAdmin):
}
if request.method == 'POST':
formset_params.update({
'data': request.POST,
'data': request.POST.copy(),
'files': request.FILES,
'save_as_new': '_saveasnew' in request.POST
})

View File

@ -205,6 +205,7 @@ class UserAdmin(admin.ModelAdmin):
# * The user has pressed the 'Save and add another' button
# * We are adding a user in a popup
if '_addanother' not in request.POST and IS_POPUP_VAR not in request.POST:
request.POST = request.POST.copy()
request.POST['_continue'] = 1
return super(UserAdmin, self).response_add(request, obj,
post_url_continue)

View File

@ -289,6 +289,7 @@ class MultiPartParser(object):
if retval:
break
self._post._mutable = False
return self._post, self._files
def handle_file_complete(self, old_field_name, counters):

View File

@ -634,6 +634,10 @@ Miscellaneous
* 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:
Features deprecated in 1.11

View File

@ -533,6 +533,25 @@ class RequestsTests(SimpleTestCase):
self.assertEqual(request.read(13), b'--boundary\r\nC')
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):
"""
If wsgi.input.read() raises an exception while trying to read() the