Bug related to the ViewSet.action
attribute
#9614
Replies: 1 comment 2 replies
-
I found this issue which asked something similar. I don't think of this as a bug, rather a limitation of the current implementation. DRF chose to initialize the request before doing anything else, and the methods you mention are used to built the request. The PS: as per the contributing page, we try to minimise changes in DRF:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
While working on a project, I came across an interesting bug that seems to have existed for a long time and fixing it is extremely straightforward.
In the DRF documentation, there’s a section titled "Introspecting ViewSet actions". The code example provided there doesn't work.
The issue arises in the
ViewSetMixin.initialize_request
method. Here, we call the parent methodinitialize_request
, which in turn invokes the methodsget_parsers
,get_authenticators
andget_content_negotiator
to create aRequest
instance. However, only after creating theRequest
instance is theaction
attribute assigned to the class.As a result, if you try to use the
action
attribute in theget_parsers
,get_authenticators
orget_content_negotiator
methods, you will encounter an error:The
ViewSetMixin.initialize_request
method can be fixed like this:Beta Was this translation helpful? Give feedback.
All reactions