-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
3.15 is raising required error on model nullable fields #9378
Comments
Could you provide a code sample of your model, serializer and data for checking? |
class Foo(...):
...
value = models.IntegerField(null=True)
class FooSerializer(serializers.ModelSerializer):
class Meta:
model = Foo
fields = '__all__'
serializer = FooSerializer(data=data) # This data does not have the "value" field
serializer.is_valid()
saved_data = serializer.save() Raises this error |
The The real issue would be how did that ever worked without a default in the first place? Usually a nullable field which is not required in forms is defined as: class Foo(...):
...
value = models.IntegerField(null=True, default=None, blank=True) |
I'm using a django v3.y.z for now, don't know if that's the problem. |
It is not documented nor in the codebase of django such behaviour for null or default. Django and the majority of DBMS does not suppose the default based on the assumption that a field is nullable. I can only guess that there is something else which is providing a value for those fields in your project (a middleware? the frontend? custom views? custom serializers? custom base models?). |
I don't think so, what I have it's pretty standard. |
Can you try your view with the @api_view(['GET','POST'])
def person(request):
if request.method == 'GET':
objs = Person.objects.all()
serializer = PeopleSerialiser(objs, many = True)
serializer.is_valid(raise_exception=True)
return Response(serializer.data) |
I have a model with nullable fields. Upgrading from 3.14 to 3.15 I'm getting this error:
AssertionError: You cannot call .save() on a serializer with invalid data.
When I print the
serializer.errors
afterserializer.is_valid()
, it says those fields are required. Is it possible that this is a bug, or do I have to manually override the field in the serializer to have therequired=False
kwarg?The text was updated successfully, but these errors were encountered: