2👍
There is a difference between partial updates, where you only update a subset of the fields on the serializer, and non-required fields, where the value can be blank.
When using partial updates, the client can send in only a subset of fields on the serializer, and the serializer will not require the ones that are not present. This has the side-effect of skipping some validation, but it expects that the fields not included in the request are already present on the model. Only the fields that are passed in with the request are validated, and only those fields are updated on the model.
You are passing in a blank value instead of not passing in the key at all. This is equivalent to doing an update that tries to clear the value of the field, which is perfectly normal in partial update situations, so Django REST Framework will run validation on the blank field. This does not appear to be documented anywhere, but that is how Django REST Framework determines what fields to run the validation on.
Because your field does not have empty=True
specified, Django REST Framework will realize that it is a required field and cannot be empty. That is why you are getting an error that says This field cannot be blank
, you are telling it to clear out the value of the field.