mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-29 21:14:01 +03:00
Merge pull request #3805 from kewama/issue-3804
Fixes #3804, avoiding update of Meta.extra_kwargs
This commit is contained in:
commit
f7025cf5e5
|
@ -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