Skip to content
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 and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for FileUploadParser with version 3.x #2399

Merged
merged 1 commit into from
Jan 12, 2015
Merged

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
@tomchristie
Copy link
Member

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)

@tomchristie tomchristie added this to the 3.0.4 Release milestone Jan 12, 2015
tomchristie added a commit that referenced this pull request Jan 12, 2015
Fix for FileUploadParser with 3.x
@tomchristie tomchristie merged commit fb0a434 into encode:master Jan 12, 2015
@tomchristie tomchristie 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