mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-10 19:56:59 +03:00
Fixes #3804, avoiding update of Meta.extra_kwargs
Added unit test to cover.
This commit is contained in:
parent
c46ed66d0a
commit
7cd3933144
|
@ -1212,7 +1212,7 @@ class ModelSerializer(Serializer):
|
|||
Return a dictionary mapping field names to a dictionary of
|
||||
additional keyword arguments.
|
||||
"""
|
||||
extra_kwargs = getattr(self.Meta, 'extra_kwargs', {})
|
||||
extra_kwargs = copy.deepcopy(getattr(self.Meta, 'extra_kwargs', {}))
|
||||
|
||||
read_only_fields = getattr(self.Meta, 'read_only_fields', None)
|
||||
if read_only_fields is not None:
|
||||
|
|
|
@ -909,3 +909,34 @@ class TestDecimalFieldMappings(TestCase):
|
|||
serializer = TestSerializer()
|
||||
|
||||
assert serializer.fields['decimal_field'].max_value == 3
|
||||
|
||||
|
||||
class TestMetaInheritance(TestCase):
|
||||
def test_extra_kwargs_not_altered(self):
|
||||
class TestSerializer(serializers.ModelSerializer):
|
||||
non_model_field = serializers.CharField()
|
||||
|
||||
class Meta:
|
||||
model = OneFieldModel
|
||||
read_only_fields = ('char_field', 'non_model_field')
|
||||
fields = read_only_fields
|
||||
extra_kwargs = {}
|
||||
|
||||
class ChildSerializer(TestSerializer):
|
||||
class Meta(TestSerializer.Meta):
|
||||
read_only_fields = ()
|
||||
|
||||
test_expected = dedent("""
|
||||
TestSerializer():
|
||||
char_field = CharField(read_only=True)
|
||||
non_model_field = CharField()
|
||||
""")
|
||||
|
||||
child_expected = dedent("""
|
||||
ChildSerializer():
|
||||
char_field = CharField(max_length=100)
|
||||
non_model_field = CharField()
|
||||
""")
|
||||
self.assertEqual(unicode_repr(ChildSerializer()), child_expected)
|
||||
self.assertEqual(unicode_repr(TestSerializer()), test_expected)
|
||||
self.assertEqual(unicode_repr(ChildSerializer()), child_expected)
|
||||
|
|
Loading…
Reference in New Issue
Block a user