Fix for FileUploadParser with version 3.x by askholme · Pull Request #2399 · encode/django-rest-framework (original) (raw)
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation2 Commits1 Checks0 Files changed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
Output from parsers ends up in a Django MergeDict and they exists elements to be dicts - not None
Right now if FileUploadParser is used then trying to access request.data['file'] will give ** TypeError: 'NoneType' object has no attribute 'getitem'
Making sure that the data part is an empty dict fixes this
Output from parsers ends up in a Django MergeDict and they exists elements to be dicts - not None
Looks reasonable, but I'm uncertain why we havn't seen any issues raised before if this is currently broken - is it newly broken in 3.x? If not it'd be super surprising as FileUploadParser
has been part of the library for quite a while now.
Can't tell as i just started using the framework.
Do note that i'm using the parser for a custom method on a viewset access request.data directly as per below. This gives an error because request.data is a mergedict where __getitem__
loops over the underlying dicts and then tries to use __getitem__
on the None returned from FileUploadParser.
Maybe the serializers use another method for access FileUploadParser data?
@list_route(methods=['put'],permission_classes=[permissions.IsAuthenticated],parser_classes= [FileUploadParser])
def raw(self,request):
img = Image(image=request.data['file'],user=self.request.user)
img.save()
return Response(ImageSerializer(img).data)
tomchristie added a commit that referenced this pull request
Fix for FileUploadParser with 3.x
tomchristie changed the title
Make FileUploadParser work with standard django API Fix for FileUploadParser with version 3.x
This was referenced
Mar 9, 2017
This was referenced
Oct 6, 2017
This was referenced
Oct 16, 2017
This was referenced
Nov 6, 2017
This was referenced
Dec 10, 2017
This was referenced
Dec 20, 2017
2 participants