Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve documentation regarding serializer class on extra actions. #6410

Closed
wants to merge 4 commits into from
Closed

Improve documentation regarding serializer class on extra actions. #6410

wants to merge 4 commits into from

Conversation

soerface
Copy link

The documentation does currently not describe how to use a custom serializer_class with extra actions. The example uses a custom serializer without using the seralizer_class attribute, resulting in the generated documentation page presenting the wrong form.

The author of the feature described the usage of the serializer_class kwarg in his PR #5605 (comment)

The documentation does currently not describe how to use a custom
`serializer_class` with extra actions. The example uses a custom
serializer without using the seralizer_class attribute, resulting in the
generated documentation page presenting the wrong form.

The author of the feature described the usage of the `serializer_class`
kwarg in his pr #5605:
#5605 (comment)
@xordoquy
Copy link
Collaborator

Hi,

Thank you for the contribution.
The issue with this PR is that it's specific to serializer_class while it could also cover throttling, permissions and so on.
I'd rather see something more opened such as "it takes as arguments the class properties such as serializer_class"

…ions." partially

This reverts commit 963607a partially.
It is just a specific example of the already documented "can take extra
arguments". The fix for the example was not reverted.
@soerface
Copy link
Author

I see, actually, right after the example, it says exactly that. I just didn't get it. Still, I would like to contribute the fix of the example code, passing the serializer_class argument (and use self.get_serializer() if I'm not mistaken, see review). I think that the example caused the confusion with me and others trying to use a custom serializer class.

Copy link
Collaborator

@carltongibson carltongibson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clarification after the example seems good.

I’m not sure about the first addition. It’s perhaps overly complex for the first example.

Maybe passing two kwargs in the second case, i.e. serializer_class as well...?

@@ -144,7 +144,7 @@ A more complete example of extra actions:
queryset = User.objects.all()
serializer_class = UserSerializer

@action(detail=True, methods=['post'])
@action(detail=True, methods=['post'], serializer_class=PasswordSerializer)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we then use self.get_serializer() in the method body? (Otherwise the kwarg isn’t doing anything...)

(Although see main comment.)

@soerface
Copy link
Author

soerface commented Jan 23, 2019

The kwarg is necessary, regardless of usage inside the function. Without the kwarg, the generated doc will show the UserSerializer form, not the PasswordSerializer form. That is the reason why I had trouble with understanding the decorator, I didn't knew how to change the form.

I feel that it might be common that extra actions have other inputs than the normal actions. Therefore I think it's a good idea to show correct usage of another serializer.

@carltongibson
Copy link
Collaborator

Hi @soerface. Yes, right. I'm thinking then we should rephrase a little bit to spell that out. (Note emphasis on little.)

Happy if you want have a pop at that. If not I'll give it a look over.

@stale
Copy link

stale bot commented Jul 31, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 31, 2022
@stale stale bot closed this Aug 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants