"AssertionError: Cannot apply DjangoModelPermissions" even when get_queryset is defined in view
<p>I'm getting the following error <strong>even though my view is overriding <code>get_queryset()</code>.</strong></p>

<pre><code>AssertionError: Cannot apply DjangoModelPermissions on a view that does not set `.queryset` or have a `.get_queryset()` method.
</code></pre>

<p>Here's my view:</p>

<pre><code>class PlayerViewSet(viewsets.ModelViewSet):

    serializer_class = PlayerSerializer

    def get_queryset(self):
        try:
            quality = self.kwargs['quality'].lower()
            print("Getting Player for %s"%quality)
            return Player.objects.filter(qualities__contains=quality)
        except:
            # todo: send out a 404
            print("No Players found for this quality :(")
            pass
</code></pre>

<p>My settings.py:</p>

<pre><code>REST_FRAMEWORK = {
    # Use Django's standard `django.contrib.auth` permissions,
    # or allow read-only access for unauthenticated users.
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
    ]
}
</code></pre>

<p><strong>Edit - Additional info:</strong> Here's the entry in urls.py:</p>

<pre><code>router = routers.DefaultRouter()
router.register(r'^player-list/(?P&lt;quality&gt;\w+)', players.views.PlayerViewSet, base_name="Player List")
[...]
urlpatterns = [
    url(r'^api/', include(router.urls)),
] 
</code></pre>

<p>I don't understand what the issue is. Why doesn't DRF see my <code>get_queryset</code> method?</p>

<p>I've tried running your code on DRF 3.3.2 and could figure out a couple of easy to miss errors that may be leading to the AssertionError you mentioned.</p>

<ol>
<li>Misspelled <code>get_queryset()</code>. Looks fine in your question here, but double check your code to be sure.</li>
<li>In your code in <code>get_queryset</code>, you return <code>None</code> in the case of an exception. I tried forcing an exception in under <code>get_queryset</code>and silencing it the way you've done (returning None at the end). This lead to the exact AssertionError. So make sure your code under <code>get_queryset</code>isn't raising any exceptions. One area where I think an exception could be raised is when the named url group 'quality' isn't passed into <code>self.kwargs</code>.</li>
</ol>

<p>Sidenote: When DRF calls the permission class' <code>has_permission</code> method, it sends the api view as an argument. It then uses the api view to figure out what your queryset is. If you can set up a debugger at 'rest_framework/permissions.py' (<a href="https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/permissions.py#L124" rel="nofollow">here</a>) and pause inside the <code>has_permission</code> method, you can then double check if the <code>queryset</code> variable is correctly picked up, or is set to None. In your case, it is probably coming up as None which is whats triggering the AssertionError, you can then check if the <code>api_view</code> instance passed on to the function as a parameter, actually refers to an instance of <code>PlayerViewSet</code> or not.</p>

python django django-rest-framework