Skip to content

Commit 2edeb74

Browse files
author
Carlton Gibson
authored
Have is_list_view recognise RetrieveModel… views (#5480)
Fixes #5165
1 parent d8da6bb commit 2edeb74

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

rest_framework/schemas/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
See schemas.__init__.py for package overview.
55
"""
6+
from rest_framework.mixins import RetrieveModelMixin
67

78

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

1617
if method.lower() != 'get':
1718
return False
19+
if isinstance(view, RetrieveModelMixin):
20+
return False
1821
path_components = path.strip('/').split('/')
1922
if path_components and '{' in path_components[-1]:
2023
return False

tests/test_schemas.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
AutoSchema, ManualSchema, SchemaGenerator, get_schema_view
2020
)
2121
from rest_framework.schemas.generators import EndpointEnumerator
22+
from rest_framework.schemas.utils import is_list_view
2223
from rest_framework.test import APIClient, APIRequestFactory
2324
from rest_framework.utils import formatting
2425
from rest_framework.views import APIView
@@ -808,3 +809,15 @@ def test_from_router(self):
808809

809810
with pytest.raises(ValueError):
810811
generator.get_schema()
812+
813+
814+
def test_is_list_view_recognises_retrieve_view_subclasses():
815+
class TestView(generics.RetrieveAPIView):
816+
pass
817+
818+
path = '/looks/like/a/list/view/'
819+
method = 'get'
820+
view = TestView()
821+
822+
is_list = is_list_view(path, method, view)
823+
assert not is_list, "RetrieveAPIView subclasses should not be classified as list views."

0 commit comments

Comments
 (0)