Fix unbound local when saving an unchanged RequestSpec
RequestSpec._get_update_primitives() tried to return the unitialized db_updates field when the object has no changes. This patch initalizes that local to None and handles that None in create() and save() where the RequestSpec._get_update_primitives() is called. Change-Id: Iad256079945bf8b5745ebdcc393c55115dbcab75 Closes-Bug: #1775863
This commit is contained in:
parent
ee7c39e441
commit
08fb09e878
|
@ -513,6 +513,7 @@ class RequestSpec(base.NovaObject):
|
||||||
it was originally scheduled with.
|
it was originally scheduled with.
|
||||||
"""
|
"""
|
||||||
updates = self.obj_get_changes()
|
updates = self.obj_get_changes()
|
||||||
|
db_updates = None
|
||||||
# NOTE(alaski): The db schema is the full serialized object in a
|
# NOTE(alaski): The db schema is the full serialized object in a
|
||||||
# 'spec' column. If anything has changed we rewrite the full thing.
|
# 'spec' column. If anything has changed we rewrite the full thing.
|
||||||
if updates:
|
if updates:
|
||||||
|
@ -538,7 +539,9 @@ class RequestSpec(base.NovaObject):
|
||||||
reason='already created')
|
reason='already created')
|
||||||
|
|
||||||
updates = self._get_update_primitives()
|
updates = self._get_update_primitives()
|
||||||
|
if not updates:
|
||||||
|
raise exception.ObjectActionError(action='create',
|
||||||
|
reason='no fields are set')
|
||||||
db_spec = self._create_in_db(self._context, updates)
|
db_spec = self._create_in_db(self._context, updates)
|
||||||
self._from_db_object(self._context, self, db_spec)
|
self._from_db_object(self._context, self, db_spec)
|
||||||
|
|
||||||
|
@ -556,7 +559,9 @@ class RequestSpec(base.NovaObject):
|
||||||
@base.remotable
|
@base.remotable
|
||||||
def save(self):
|
def save(self):
|
||||||
updates = self._get_update_primitives()
|
updates = self._get_update_primitives()
|
||||||
db_spec = self._save_in_db(self._context, self.instance_uuid, updates)
|
if updates:
|
||||||
|
db_spec = self._save_in_db(self._context, self.instance_uuid,
|
||||||
|
updates)
|
||||||
self._from_db_object(self._context, self, db_spec)
|
self._from_db_object(self._context, self, db_spec)
|
||||||
self.obj_reset_changes()
|
self.obj_reset_changes()
|
||||||
|
|
||||||
|
|
|
@ -667,6 +667,16 @@ class _TestRequestSpecObject(object):
|
||||||
primitive = destination.obj_to_primitive(target_version='1.0')
|
primitive = destination.obj_to_primitive(target_version='1.0')
|
||||||
self.assertNotIn('aggregates', primitive['nova_object.data'])
|
self.assertNotIn('aggregates', primitive['nova_object.data'])
|
||||||
|
|
||||||
|
def test_create_raises_on_unchanged_object(self):
|
||||||
|
ctxt = context.RequestContext(uuids.user_id, uuids.project_id)
|
||||||
|
req_obj = request_spec.RequestSpec(context=ctxt)
|
||||||
|
self.assertRaises(exception.ObjectActionError, req_obj.create)
|
||||||
|
|
||||||
|
def test_save_can_be_called_on_unchanged_object(self):
|
||||||
|
req_obj = fake_request_spec.fake_spec_obj(remove_id=True)
|
||||||
|
req_obj.create()
|
||||||
|
req_obj.save()
|
||||||
|
|
||||||
|
|
||||||
class TestRequestSpecObject(test_objects._LocalTest,
|
class TestRequestSpecObject(test_objects._LocalTest,
|
||||||
_TestRequestSpecObject):
|
_TestRequestSpecObject):
|
||||||
|
|
Loading…
Reference in New Issue