Skip to content

Commit d9b4f63

Browse files
author
Ryan P Kilby
committed
Fix schema disabling for extra actions
1 parent 070b4d0 commit d9b4f63

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

rest_framework/schemas/generators.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ def should_include_endpoint(self, path, callback):
218218
if callback.cls.schema is None:
219219
return False
220220

221+
if 'schema' in callback.initkwargs:
222+
if callback.initkwargs['schema'] is None:
223+
return False
224+
221225
if path.endswith('.{format}') or path.endswith('.{format}/'):
222226
return False # Ignore .json style URLs.
223227

rest_framework/schemas/inspectors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ def __get__(self, instance, owner):
157157

158158
def __set__(self, instance, other):
159159
self.instance_schemas[instance] = other
160-
other.view = instance
160+
if other is not None:
161+
other.view = instance
161162

162163
@property
163164
def view(self):

tests/test_schemas.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ def custom_list_action(self, request):
9999
def custom_list_action_multiple_methods(self, request):
100100
return super(ExampleViewSet, self).list(self, request)
101101

102+
@action(detail=False, schema=None)
103+
def excluded_action(self, request):
104+
pass
105+
102106
def get_serializer(self, *args, **kwargs):
103107
assert self.request
104108
assert self.action
@@ -737,6 +741,19 @@ def extra_action(self, pk, **kwargs):
737741
assert len(fields) == 2
738742
assert "my_extra_field" in [f.name for f in fields]
739743

744+
def test_viewset_action_with_null_schema(self):
745+
class CustomViewSet(GenericViewSet):
746+
@action(detail=True, schema=None)
747+
def extra_action(self, pk, **kwargs):
748+
pass
749+
750+
router = SimpleRouter()
751+
router.register(r'detail', CustomViewSet, base_name='detail')
752+
753+
generator = SchemaGenerator()
754+
view = generator.create_view(router.urls[0].callback, 'GET')
755+
assert view.schema is None
756+
740757
def test_view_with_manual_schema(self):
741758

742759
path = '/example'

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy