mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-23 01:57:00 +03:00
parent
dd850df1d8
commit
8af366a732
|
@ -1381,7 +1381,13 @@ class ListField(Field):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.child = kwargs.pop('child', copy.deepcopy(self.child))
|
self.child = kwargs.pop('child', copy.deepcopy(self.child))
|
||||||
self.allow_empty = kwargs.pop('allow_empty', True)
|
self.allow_empty = kwargs.pop('allow_empty', True)
|
||||||
|
|
||||||
assert not inspect.isclass(self.child), '`child` has not been instantiated.'
|
assert not inspect.isclass(self.child), '`child` has not been instantiated.'
|
||||||
|
assert self.child.source is None, (
|
||||||
|
"The `source` argument is not meaningful when applied to a `child=` field. "
|
||||||
|
"Remove `source=` from the field declaration."
|
||||||
|
)
|
||||||
|
|
||||||
super(ListField, self).__init__(*args, **kwargs)
|
super(ListField, self).__init__(*args, **kwargs)
|
||||||
self.child.bind(field_name='', parent=self)
|
self.child.bind(field_name='', parent=self)
|
||||||
|
|
||||||
|
@ -1424,7 +1430,13 @@ class DictField(Field):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.child = kwargs.pop('child', copy.deepcopy(self.child))
|
self.child = kwargs.pop('child', copy.deepcopy(self.child))
|
||||||
|
|
||||||
assert not inspect.isclass(self.child), '`child` has not been instantiated.'
|
assert not inspect.isclass(self.child), '`child` has not been instantiated.'
|
||||||
|
assert self.child.source is None, (
|
||||||
|
"The `source` argument is not meaningful when applied to a `child=` field. "
|
||||||
|
"Remove `source=` from the field declaration."
|
||||||
|
)
|
||||||
|
|
||||||
super(DictField, self).__init__(*args, **kwargs)
|
super(DictField, self).__init__(*args, **kwargs)
|
||||||
self.child.bind(field_name='', parent=self)
|
self.child.bind(field_name='', parent=self)
|
||||||
|
|
||||||
|
|
|
@ -1416,6 +1416,15 @@ class TestListField(FieldValues):
|
||||||
]
|
]
|
||||||
field = serializers.ListField(child=serializers.IntegerField())
|
field = serializers.ListField(child=serializers.IntegerField())
|
||||||
|
|
||||||
|
def test_no_source_on_child(self):
|
||||||
|
with pytest.raises(AssertionError) as exc_info:
|
||||||
|
serializers.ListField(child=serializers.IntegerField(source='other'))
|
||||||
|
|
||||||
|
assert str(exc_info.value) == (
|
||||||
|
"The `source` argument is not meaningful when applied to a `child=` field. "
|
||||||
|
"Remove `source=` from the field declaration."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestEmptyListField(FieldValues):
|
class TestEmptyListField(FieldValues):
|
||||||
"""
|
"""
|
||||||
|
@ -1461,6 +1470,15 @@ class TestDictField(FieldValues):
|
||||||
]
|
]
|
||||||
field = serializers.DictField(child=serializers.CharField())
|
field = serializers.DictField(child=serializers.CharField())
|
||||||
|
|
||||||
|
def test_no_source_on_child(self):
|
||||||
|
with pytest.raises(AssertionError) as exc_info:
|
||||||
|
serializers.DictField(child=serializers.CharField(source='other'))
|
||||||
|
|
||||||
|
assert str(exc_info.value) == (
|
||||||
|
"The `source` argument is not meaningful when applied to a `child=` field. "
|
||||||
|
"Remove `source=` from the field declaration."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestUnvalidatedDictField(FieldValues):
|
class TestUnvalidatedDictField(FieldValues):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user