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

AttributeError after update to 0.5.0 #40

Closed
Rubyj opened this issue Apr 17, 2019 · 3 comments
Closed

AttributeError after update to 0.5.0 #40

Rubyj opened this issue Apr 17, 2019 · 3 comments

Comments

@Rubyj
Copy link

Rubyj commented Apr 17, 2019

I have written my own ViewSet that extends rest_framework.viewsets.ViewSet

Since the update to 0.5.0 a function I have written for this ViewSet crashes. I have the following function to make sure I get datatables filtering:

    def filter_queryset(self, queryset):
        for backend in list(self.filter_backends):
            queryset = backend().filter_queryset(self.request, queryset, self)
        return queryset

After the update to 0.5.0 the call to filter_queryset() errors out on the following line:

total_count = view.get_queryset().count()

Due to the fact that my view does not have a get_queryset() method as can be seen here:

web_1      |   File "/usr/lib/python3.6/site-packages/rest_framework_datatables/filters.py", line 18, in filter_queryset
web_1      |     total_count = view.get_queryset().count()
web_1      | AttributeError: 'ValidationSummaryViewSet' object has no attribute 'get_queryset'

Does this mean I now need to implement a get_queryset() method in my ViewSet? I am not sure I 100% understand this change. Thanks.

@izimobil
Copy link
Owner

This change was introduced in this commit: 4db3d6b, that solves an issue when multiple filter backends are used (total count was wrong).

IMHO, if your view is dealing with a ModelSerializer, you best option is to write a get_queryset() method, because even if we patch drf-datatables, I suspect other DRF third party apps will also assume that method exists anyway.

@Rubyj
Copy link
Author

Rubyj commented Apr 30, 2019

@izimobil My view is actually dealing with a normal Serializer because I'm not really displaying one particular model with my serializer. Anyways, I just implemented the same get_queryset() I found in GenericAPIView and I no longer get the error. Do you think this is ok for a trivial use case?

@izimobil
Copy link
Owner

I think it does the job :) closing the issue. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants