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

Have is_list_view recognise RetrieveModel… views #5480

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions rest_framework/schemas/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

See schemas.__init__.py for package overview.
"""
from rest_framework.mixins import RetrieveModelMixin


def is_list_view(path, method, view):
Expand All @@ -15,6 +16,8 @@ def is_list_view(path, method, view):

if method.lower() != 'get':
return False
if isinstance(view, RetrieveModelMixin):
return False
path_components = path.strip('/').split('/')
if path_components and '{' in path_components[-1]:
return False
Expand Down
13 changes: 13 additions & 0 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
AutoSchema, ManualSchema, SchemaGenerator, get_schema_view
)
from rest_framework.schemas.generators import EndpointEnumerator
from rest_framework.schemas.utils import is_list_view
from rest_framework.test import APIClient, APIRequestFactory
from rest_framework.utils import formatting
from rest_framework.views import APIView
Expand Down Expand Up @@ -808,3 +809,15 @@ def test_from_router(self):

with pytest.raises(ValueError):
generator.get_schema()


def test_is_list_view_recognises_retrieve_view_subclasses():
class TestView(generics.RetrieveAPIView):
pass

path = '/looks/like/a/list/view/'
method = 'get'
view = TestView()

is_list = is_list_view(path, method, view)
assert not is_list, "RetrieveAPIView subclasses should not be classified as list views."