MultipleChoiceField doesn't use default value if not required #8558
Unanswered
RukosenpaIneligible
asked this question in
Potential Issue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have some serializer using for validation of query parameters
So, if i try to pass an empty
QueryDict()
(reminder:request.query_params
also generateQueryDict
) instance as an argument to that serializer i expect to get validated data with default values like this:and response:
But instead i got this:
But this doesn't happen because in this string we call
getlist
method ofQueryDict
without passing default argument, so it will call withdefault=None
argument. As a result this string executes, and we get empty list instead.Then when we run validators in this string we call
validate_empty_values
method which returns default values for all kind of serializer fields. But this triggers only if passed data isempty
constant. In this serializer setup we never get our default value because conditions for its triggering never occurs.Beta Was this translation helpful? Give feedback.
All reactions