mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-03 12:00:12 +03:00
more explicit/obvious error if you try to do writable dotted field.source with a callable final component
This commit is contained in:
parent
0ab70ba170
commit
d5d97624f7
|
@ -69,6 +69,9 @@ def set_component(obj, attr_name, value):
|
||||||
if isinstance(obj, dict):
|
if isinstance(obj, dict):
|
||||||
obj[attr_name] = value
|
obj[attr_name] = value
|
||||||
else:
|
else:
|
||||||
|
attr = getattr(obj, attr_name)
|
||||||
|
if six.callable(attr):
|
||||||
|
raise TypeError("%r.%s is a method; can't set it" % (obj, attr_name))
|
||||||
setattr(obj, attr_name, value)
|
setattr(obj, attr_name, value)
|
||||||
|
|
||||||
|
|
||||||
|
@ -336,10 +339,6 @@ class WritableField(Field):
|
||||||
item = obj
|
item = obj
|
||||||
for component in parts:
|
for component in parts:
|
||||||
item = get_component(item, component)
|
item = get_component(item, component)
|
||||||
if item is None:
|
|
||||||
raise ValueError(
|
|
||||||
"can't set %r: component %r is None" % (source, component)
|
|
||||||
)
|
|
||||||
set_component(item, last_source_part, value)
|
set_component(item, last_source_part, value)
|
||||||
|
|
||||||
def field_from_native(self, data, files, field_name, into):
|
def field_from_native(self, data, files, field_name, into):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user