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
_writable_fields in Serializer retrieves read only fields #4666
Comments
I don't get your issue. |
I'm having this issue with fields like
The nested writes test complains about this field when it shouldn't.
|
@danielkeller I'm looking into this issue right now (branch, PR tomorrow). Can you show me the error and the end of your traceback? All data is good. |
I'm going to reopen this. It'll give me something to close. 🙂 |
Related: #5708 (comment) |
Closed in #5886 |
Hi,
the _writable_fields in the Serializer class decides if a field is writeable or not is this way:
if (not field.read_only) or (field.default is not empty)
This has caused an issue for us. I have a serializer with 3 nested fields that are defined as read only. So when I send the serializer to the client, these fields are not empty. When I want to update this object and send the data back to the server, these fields are again not empty. The fields are not changed, since it's read only, they just have the same data they had before.
But when I reach the validation point, because this fields are not empty, they are added to the writeable_fields list, even though they are defined as read only, like this:
offer = OfferSerializer(read_only=True)
In this case, when we tried to update the object we got this error:
The
.update()
method does not support writable nested fields by default.Write an explicit
.update()
method for serializer...The text was updated successfully, but these errors were encountered: