Merge "Improved error message for Object.coerce"

This commit is contained in:
Jenkins 2016-07-05 19:45:51 +00:00 committed by Gerrit Code Review
commit fb819b8b87
1 changed files with 9 additions and 2 deletions

View File

@ -658,10 +658,17 @@ class Object(FieldType):
# If we're not dealing with an object, it's probably a
# primitive so get it's type for the message below.
obj_name = type(value).__name__
obj_mod = ''
if hasattr(obj, '__module__'):
obj_mod = ''.join([obj.__module__, '.'])
val_mod = ''
if hasattr(value, '__module__'):
val_mod = ''.join([value.__module__, '.'])
raise ValueError(_('An object of type %(type)s is required '
'in field %(attr)s, not a %(valtype)s') %
{'type': self._obj_name, 'attr': attr,
'valtype': obj_name})
{'type': ''.join([obj_mod, self._obj_name]),
'attr': attr, 'valtype': ''.join([val_mod,
obj_name])})
return value
@staticmethod