object value errors do not all indicate which field was involved

Bug #1430681 reported by Paul Murray
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Low
Paul Murray
oslo.versionedobjects
Fix Released
Low
Davanum Srinivas (DIMS)

Bug Description

When a value is assigned to an object field it is type checked in the coerce() method for the field and a ValueError exception is raised if it is not of the appropriate type. The name of the field involved in the check is known in the coerce() method, but in most cases it is not mentioned in the error message. When constructing an object with a list of field values it is hard to know which one caused the error. Adding the name of the field that generated the error would help.

For example, this test:

    def test_my_dummy_test(self):
        i = instance.Instance(uuid='my id', system_metadata='metadata')

This would this would result in a ValueError exception as follows:

Traceback (most recent call last):
  File "/home/ptm/code/nova/nova/tests/unit/objects/test_instance.py", line 1514, in test_my_dummy_test
    i = instance.Instance(uuid='my id', system_metadata='metadata')
  File "/home/ptm/code/nova/nova/objects/instance.py", line 270, in __init__
    super(Instance, self).__init__(*args, **kwargs)
  File "/home/ptm/code/nova/nova/objects/base.py", line 282, in __init__
    setattr(self, key, kwargs[key])
  File "/home/ptm/code/nova/nova/objects/base.py", line 77, in setter
    field_value = field.coerce(self, name, value)
  File "/home/ptm/code/nova/nova/objects/fields.py", line 191, in coerce
    return self._type.coerce(obj, attr, value)
  File "/home/ptm/code/nova/nova/objects/fields.py", line 433, in coerce
    raise ValueError(_('A dict is required in field %s') % attr)
ValueError: A dict is required here

This does not give any clue which of the two values supplied is incorrect. Adding the field name to error message could give an error like this:

ValueError: A dict is required in field system_metadata

Paul Murray (pmurray)
Changed in nova:
assignee: nobody → Paul Murray (pmurray)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

Fix proposed to branch: master
Review: https://review.openstack.org/163328

Changed in nova:
status: New → In Progress
Changed in nova:
importance: Undecided → Low
Changed in oslo.versionedobjects:
assignee: nobody → Davanum Srinivas (DIMS) (dims-v)
importance: Undecided → Low
status: New → In Progress
Changed in nova:
assignee: Paul Murray (pmurray) → Davanum Srinivas (DIMS) (dims-v)
Changed in nova:
assignee: Davanum Srinivas (DIMS) (dims-v) → Paul Murray (pmurray)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.openstack.org/163328
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=c05dfbc70c8a386a49c4ea33c32b56f6fe2c0d9d
Submitter: Jenkins
Branch: master

commit c05dfbc70c8a386a49c4ea33c32b56f6fe2c0d9d
Author: Paul Murray <email address hidden>
Date: Wed Mar 11 08:37:59 2015 +0000

    Add field name to error messages in object type checking

    The coerce() methods in object fields generate ValueError
    exceptions if an incorrect type is used. Most of the messages
    do not indicate which field was involved although that information
    is available in the coerce() methods. This change adds the
    field name to the error messages.

    Change-Id: Ic94d52f6019c5a5a291675e321f96f5c65beaf10
    Closes-Bug: #1430681

Changed in nova:
status: In Progress → Fix Committed
Revision history for this message
Davanum Srinivas (DIMS) (dims-v) wrote :
Changed in oslo.versionedobjects:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in nova:
milestone: none → liberty-1
status: Fix Committed → Fix Released
Changed in oslo.versionedobjects:
milestone: none → 0.5.0
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in nova:
milestone: liberty-1 → 12.0.0
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.