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_requestmethod. Here, we call the parent methodinitialize_request, which in turn invokes the methodsget_parsers,get_authenticatorsandget_content_negotiatorto create aRequestinstance. However, only after creating theRequestinstance is theactionattribute assigned to the class.As a result, if you try to use the
actionattribute in theget_parsers,get_authenticatorsorget_content_negotiatormethods, you will encounter an error:The
ViewSetMixin.initialize_requestmethod can be fixed like this:Beta Was this translation helpful? Give feedback.
All reactions