Skip to content

When a serializer field defined explicitly, extra_kwargs for that field are ignored #6581

Closed
@ozgurakcali

Description

@ozgurakcali

Steps to reproduce

Define a field explicity on a serializer, than add extra_kwargs for that field in the Meta class

class MySerializer(serializers.ModelSerializer):
    my_field = serializer.CharField()

    class Meta:
        model = MyModel
        fields = '__all__'
        extra_kwargs = {
            'my_field ': {'required': False}
        }

Expected behavior

Should not raise validation error when my_field is not supplied in the request body

Actual behavior

Raises validation error for missing my_field

I think this behavior is caused by this part in get_fields method.

If this is the expected behavior though, which could be taking possible clashing settings into consideration, I think the documentation should be updated stating that extra_kwargs will not be taken into account if the field is defined explicitly in the serializer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions