From cefc47890a7c3b14d28bba7231f79745ed87706e Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 10 Jul 2018 13:55:17 +0200 Subject: [PATCH 1/3] Handle "suffix" used in action decorator kwargs With 0148a9f8d you would get a TypeError when using "suffix" in an action decorator. This might get improved to take suffix as a keyword argument already, defaulting to `None`. --- rest_framework/decorators.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rest_framework/decorators.py b/rest_framework/decorators.py index 60078947f..44ecb4b9d 100644 --- a/rest_framework/decorators.py +++ b/rest_framework/decorators.py @@ -154,9 +154,12 @@ def action(methods=None, detail=None, name=None, url_path=None, url_name=None, * func.url_name = url_name if url_name else func.__name__.replace('_', '-') func.kwargs = kwargs func.kwargs.update({ - 'name': func.name, 'description': func.__doc__ or None }) + if 'suffix' not in kwargs: + func.kwargs.update({ + 'name': func.name, + }) return func return decorator From f2d0809816d3350b4c7c71bcf537c78977e29260 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 10 Jul 2018 14:16:40 +0200 Subject: [PATCH 2/3] fixup! Handle "suffix" used in action decorator kwargs --- tests/test_decorators.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_decorators.py b/tests/test_decorators.py index 7568513f3..f42e2e7c6 100644 --- a/tests/test_decorators.py +++ b/tests/test_decorators.py @@ -187,6 +187,16 @@ class ActionDecoratorTestCase(TestCase): 'description': 'Description', } + def test_detail_suffix(self): + @action(detail=True, suffix='Suffix') + def test_action(request): + raise NotImplementedError + + assert test_action.kwargs == { + 'description': None, + 'suffix': 'Suffix', + } + def test_detail_required(self): with pytest.raises(AssertionError) as excinfo: @action() From 38c53cf2106072b10975f9516cd4cf10087177bf Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 10 Jul 2018 14:21:22 +0200 Subject: [PATCH 3/3] fixup! fixup! Handle "suffix" used in action decorator kwargs --- rest_framework/decorators.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rest_framework/decorators.py b/rest_framework/decorators.py index 44ecb4b9d..fb33d83c1 100644 --- a/rest_framework/decorators.py +++ b/rest_framework/decorators.py @@ -157,9 +157,7 @@ def action(methods=None, detail=None, name=None, url_path=None, url_name=None, * 'description': func.__doc__ or None }) if 'suffix' not in kwargs: - func.kwargs.update({ - 'name': func.name, - }) + func.kwargs['name'] = func.name return func return decorator