question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AssertionError with ViewSets

See original GitHub issue

I’m using Python 3.6.3, Django 1.11.6, DRF 3.7.7, version 2.0.1 of this library, and FlatMultipleModelAPIViewSet.

The issue I’m having is:

AssertionError at <URI>
<ViewSet>.get_queryset() returned None
...
Exception Location: <Path>/rest_framework/permissions.py in _queryset, line 126

This is in the code here:

class FlatMultipleModelAPIViewSet(FlatMultipleModelMixin, GenericViewSet):
    def get_queryset(self):
        return None

And it’s running up against this check:

if hasattr(view, 'get_queryset'):
    queryset = view.get_queryset()
    assert queryset is not None, (
        '{}.get_queryset() returned None'.format(view.__class__.__name__)
    )
    return queryset

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
MattBroachcommented, May 27, 2020

Hi @amar-muratovic, can you provide some sample code to reproduce the issue? It’s very hard to answer without knowing the specifics of your code.

Also, this seems like a separate issue than the one under discussion here. I’d recommend opening a new issue rather than continuing this current (probably unrelated) discussion.

1reaction
rlabrecquecommented, Nov 22, 2018

This pointed me in the right direction, All I really needed was

from rest_framework import permissions

class MultipleModelPermissions(permissions.DjangoModelPermissions):
    def has_permission(self, request, view):
        # Workaround to ensure DjangoModelPermissions are not applied
        # to the root view when using DefaultRouter.
        return True

MyMultipleModelViewset(FlatMultipleModelAPIViewSet):
     permission_classes = (MultipleModelPermissions,)

The only note is that a trailing s was missing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Assertion error parsing response to POST request from DRF ...
Assertion error parsing response to POST request from DRF viewset with DRF APIClient in tests ... serializers, viewsets router = routers.
Read more >
Routers - Django REST framework
Resource routing allows you to quickly declare all of the common routes for a given resourceful controller. Instead of declaring separate routes for...
Read more >
Django-Rest-Framework - Obey the Testing Goat!
A router is DRF's way of building URL configuration automatically, and mapping them to the functionality provided by the ViewSet. At this point ......
Read more >
Using Different Read and Write Serializers in Django REST ...
The first way we approached using different serializers for read and update actions was to override get_serializer_class() on each viewset to ...
Read more >
self.assertEqual(response.status_code, status.HTTP_200_OK ...
HTTP_200_OK) AssertionError: 404 ! ... from rest_framework import generics, mixins, viewsets from rest_framework.filters import SearchFilter from ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found