Skip to content

_writable_fields in Serializer retrieves read only fields #4666

Closed
@vasofi

Description

@vasofi

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions