From 117c77400bce176269d8030f448ca2372abcd0de Mon Sep 17 00:00:00 2001 From: exg1o Date: Tue, 28 Jan 2025 19:24:00 +0200 Subject: [PATCH 1/2] Fix `Introspecting ViewSet actions` docs section --- docs/api-guide/viewsets.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/api-guide/viewsets.md b/docs/api-guide/viewsets.md index 43007e95df..7f2b3c2c77 100644 --- a/docs/api-guide/viewsets.md +++ b/docs/api-guide/viewsets.md @@ -128,6 +128,8 @@ You may inspect these attributes to adjust behavior based on the current action. permission_classes = [IsAdminUser] return [permission() for permission in permission_classes] +**Note**: don't use the `action` attribute in the `get_parsers`, `get_authenticators` or `get_content_negotiator` methods, otherwise you will get an `AttributeError` error. + ## Marking extra actions for routing If you have ad-hoc methods that should be routable, you can mark them as such with the `@action` decorator. Like regular actions, extra actions may be intended for either a single object, or an entire collection. To indicate this, set the `detail` argument to `True` or `False`. The router will configure its URL patterns accordingly. e.g., the `DefaultRouter` will configure detail actions to contain `pk` in their URL patterns. From b739dff2008dc7233b207a217a20403a92ab7393 Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Tue, 28 Jan 2025 18:03:51 +0000 Subject: [PATCH 2/2] Update docs/api-guide/viewsets.md --- docs/api-guide/viewsets.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api-guide/viewsets.md b/docs/api-guide/viewsets.md index 7f2b3c2c77..22acfe327a 100644 --- a/docs/api-guide/viewsets.md +++ b/docs/api-guide/viewsets.md @@ -128,7 +128,7 @@ You may inspect these attributes to adjust behavior based on the current action. permission_classes = [IsAdminUser] return [permission() for permission in permission_classes] -**Note**: don't use the `action` attribute in the `get_parsers`, `get_authenticators` or `get_content_negotiator` methods, otherwise you will get an `AttributeError` error. +**Note**: the `action` attribute is not available in the `get_parsers`, `get_authenticators` and `get_content_negotiator` methods, as it is set _after_ they are called in the framework lifecycle. If you override one of these methods and try to access the `action` attribute in them, you will get an `AttributeError` error. ## Marking extra actions for routing