Improved error message for Object.coerce

Include the full path to the module in the error message
for both the expected and actual object.

Change-Id: I2b5ff3afdbc622a66ba9f78cf8ed61d892694793
Closes-Bug: 1592625
This commit is contained in:
John Perkins 2016-06-14 20:08:56 -06:00
parent 38f790f020
commit 238fd1954a
1 changed files with 9 additions and 2 deletions

View File

@ -627,10 +627,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