Skip to content

Commit

Permalink
Fix empty viewset compatibility w/ browsable API (#263)
Browse files Browse the repository at this point in the history
* Add rendering to 'disabled' viewset test
* Allow views with empty filterset_class
  • Loading branch information
Ryan P Kilby committed Jul 29, 2018
1 parent 2fba26e commit aa50d18
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rest_framework_filters/backends.py
Expand Up @@ -29,6 +29,10 @@ def patch_for_rendering(self, request):
def get_filterset_class(view, queryset=None):
filterset_class = original(view, queryset)

# Don't break if filterset_class is not provided
if filterset_class is None:
return None

# django-filter compatibility
if issubclass(filterset_class, FilterSet):
filterset_class = filterset_class.disable_subset(depth=1)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_backends.py
Expand Up @@ -106,6 +106,11 @@ def test_disabled(self):
# filterset should be None, method should not error
self.assertIsNone(backend().get_filterset(request, view.queryset, view))

# patched method should not error
backend = backend()
with backend.patch_for_rendering(request):
self.assertIsNone(backend.get_filterset(request, view.queryset, view))


class BackendRenderingTests(APITestCase):

Expand Down

0 comments on commit aa50d18

Please sign in to comment.