-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Fix bug in validators documentation #8779
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
Conversation
Function validators seem to have to return their value (which will become part of `validated_data`) as part of their signature.
I believe it's a mistake. There is no much difference between function based and class based validators. These are just two different ways to provide a callable, and the returned values are not used. In contrast to this, |
are you suggesting to revert this? |
Are you sure about that @Ariki. I think you are right for the validators that come with Django but it seems behaviour of dango-rest is a bit different here, but I might be off. If I just run a test and trace the stack I eventually end up here:
I don't have time to create a simple example to reproduce right now, but I remember I initiated this change because I was running into unexplainable null values suddenly when adding validators which seems to agree with the snippet above. |
The code line above is responsible for running validation methods of a serializer which indeed should return a value. The class-based and function-based validators are run in django-rest-framework/rest_framework/fields.py Lines 560 to 563 in 48a21aa
So yes, I suggest to revert this. |
Ok I see what you are mean. You are right indeed, but I must say I find that difference in behaviour of those two than rather confusing to be honest. Any design choice that's behind that? |
opened a revert PR |
Function validators seem to have to return their value (which will become part of
validated_data
) as part of their signature.Note: Before submitting this pull request, please review our contributing guidelines.
Description
Please describe your pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue. When linking to an issue, please use
refs #...
in the description of the pull request.