You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the value of Meta.extra_kwargs is updated, it causes side effects for child serializers that inherit from Meta. (I know that this is officially not recommended, but the doc does show how to do it.) For example:
>>> from django.contrib.auth.models import User
>>> from rest_framework import serializers
>>>
>>> class UserSerializer(serializers.ModelSerializer):
... class Meta:
... model = User
... read_only_fields = ('username', 'email')
... fields = read_only_fields
... extra_kwargs = {}
...
>>> class ChildUserSerializer(UserSerializer):
... class Meta(UserSerializer.Meta):
... read_only_fields = ()
...
Before instantiating the base class, the child class looks correct:
ModelSerializer.get_extra_kwargs() currently does:
If extra_kwargs is defined in the Meta class, this alters the value of it. To avoid this, get_extra_kwargs() should update a copy of it:
When the value of Meta.extra_kwargs is updated, it causes side effects for child serializers that inherit from Meta. (I know that this is officially not recommended, but the doc does show how to do it.) For example:
Before instantiating the base class, the child class looks correct:
But after instantiating the base class, the child class' Meta.extra_kwargs is corrupted:
The text was updated successfully, but these errors were encountered: