Repository navigation
MultiPartParser throws a KeyError if parser_context is not provided #9847
Replies: 1 comment
|
Confirmed on DRF 3.18.0 — and >>> MultiPartParser().parse(io.BytesIO(b"x"), media_type="multipart/form-data; boundary=abc", parser_context=None)
KeyError: 'request'
>>> MultiPartParser().parse(io.BytesIO(b"x"), media_type="multipart/form-data; boundary=abc", parser_context={})
KeyError: 'request'The reason it reads as optional is that the signature is shared across all parsers — In normal use you never hit this, because If you're calling it directly, pass a real request: from rest_framework.test import APIRequestFactory
wsgi = APIRequestFactory().post("/", {"file": f}, format="multipart")
MultiPartParser().parse(wsgi, media_type=wsgi.content_type, parser_context={"request": wsgi})Whether the fix should be a clearer |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
If you try to use MultiPartParser without providing a request object in parser_context, it will throw a KeyError.
It seems to be that parser_context is required and can't be None.
All reactions