Skip to content

Conversation

@askholme
Copy link
Contributor

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
@lovelydinosaur
Copy link
Contributor

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.

@askholme
Copy link
Contributor Author

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)

@lovelydinosaur lovelydinosaur added this to the 3.0.4 Release milestone Jan 12, 2015
lovelydinosaur added a commit that referenced this pull request Jan 12, 2015
Fix for FileUploadParser with 3.x
@lovelydinosaur lovelydinosaur merged commit fb0a434 into encode:master Jan 12, 2015
@lovelydinosaur lovelydinosaur changed the title Make FileUploadParser work with standard django API Fix for FileUploadParser with version 3.x Jan 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants