Catch errors during parsing and set empty .DATA/.FILES before re-raising.

This commit is contained in:
Tom Christie 2013-12-03 08:58:05 +00:00
parent fe4c7d4000
commit c1d9a96df0

View File

@ -356,7 +356,16 @@ class Request(object):
if not parser:
raise exceptions.UnsupportedMediaType(media_type)
parsed = parser.parse(stream, media_type, self.parser_context)
try:
parsed = parser.parse(stream, media_type, self.parser_context)
except:
# If we get an exception during parsing, fill in empty data and
# re-raise. Ensures we don't simply repeat the error when
# attempting to render the browsable renderer response, or when
# logging the request or similar.
self._data = QueryDict('', self._request._encoding)
self._files = MultiValueDict()
raise
# Parser classes may return the raw data, or a
# DataAndFiles object. Unpack the result as required.