Django-rest-framework: ContentType matching query does not exist cause when UserViewSet uses DjangoObjectPermissionsFilter

Created on 1 Aug 2015  路  6Comments  路  Source: encode/django-rest-framework

I have the following UserViewSet:

class UserViewSet(viewsets.ReadOnlyModelViewSet):
    queryset = User.objects.all()
    serializer_class = UserSerializer
    permission_classes = (CustomObjectPermissions,)
    filter_backends = (filters.DjangoObjectPermissionsFilter,)

When using the api browser to view the User list or a User, I get the error DoesNotExist ... ContentType matching query does not exist.

This error does not occur for other viewsets. It appears to be an issue with the django-guardian shortcut get_objects_for_user(). I've read of similar issues and it seems it relates to django-rest passing the permission as unicode (in this case, u'view_user').

Most helpful comment

The issued ended up being that the view_user permission wasn't set for User (painfully obvious in retrospect). Thanks for the helpful prompts.

All 6 comments

What versions of guardian and rest framework? If you subclass the filter and ensure that it passes binary/str values instead does that resolve the issue? Can you trivially reproduce this in a new project?

The issued ended up being that the view_user permission wasn't set for User (painfully obvious in retrospect). Thanks for the helpful prompts.

@mcastle thanks for the follow up.

I'm running into the same issue. I don't understand what the proposed solution is. @mcastle Would you mind elaborating?

Never mind, figured it out. Sorry for the inconvenience.

@mcastle i'm facing the same issue and I saw your answer here http://stackoverflow.com/questions/7724265/how-to-add-custom-permission-to-the-user-model-in-django as well. I simply added the code to my django project __init__.py. Is there anything else to do?

Was this page helpful?
0 / 5 - 0 ratings