I’m working on some legacy Django code. I have two nearly-identical views:
@login_required
def foo(request):
assert False, "foo mutable=%s" % request.POST._mutable
@login_required
def bar(request):
assert False, "foo mutable=%s" % request.POST._mutable
Strangely _mutable is True for one of the handlers and False for the other.
There is no custom middleware and the stack traces on the resulting Django debug page are practically the same.
Sure, I can get around the problem by using request.POST.copy() or request.POST._mutable = True to make the/a QueryDict object mutable, but I’d like to know what could be causing this.
By default it should always be
False, the only place in the Django code that sets it toTrueis in theMultiPartParser.parse, which only happens if theCONTENT_TYPEstarts withmultipart.From
_load_post_and_filesinHttpRequest:From
parse_file_upload:And from
MultiPartParser.parse:So if one view is getting multipart requests and the other is not, that would explain the difference.