IntegerField declared as blank=True,null=True
on model, and part of a unique_together
, is showing up as required=True
in default model serializer
#9538
Unanswered
uraniumanchor
asked this question in
Potential Issue
Replies: 1 comment
-
This is some great debugging work! Some of these findings explain the behaviour reported in #9378 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Fields/Meta are declared thus in my models file (heavily trimmed down for relevancy):
But when trying to use a default
ModelSerializer
to create, if the field is not included in the POST data, it complains that the field is required.I think I tracked down the issue to these lines in
get_uniqueness_extra_kwargs
:There are lines in
get_field_kwargs
infield_mapping.py
later on that do the right thing:However, in
get_fields
it combines these (incorrectly?) and the former overrides the latter:Inspecting the values in the debugger immediately before this block looks like this:
Afterwards,
required
has changed toTrue
.Additionally, the
UniqueTogetherValidator
does not seem to take into account the nullability of the field and triggers a validation error.Setting
'required': False
explicitly on the Serializer'sMeta.extra_kwargs
field fixes the former, but'default': None
is required to fix the latter. Setting'default': None
by itself causes an assertion error thandefault
cannot be provided ifrequired
isTrue
.Beta Was this translation helpful? Give feedback.
All reactions