From 1b9961c4b6785d85e98223f576bd839c0212b3a7 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Mon, 17 Jun 2013 19:10:10 +0000 Subject: Fix instance obj refresh() The refresh() method pulls a fresh copy of the instance but if any fields changed when doing so, they are left marked as changes that are not yet committed. Also clarified the doc string for obj_what_changed() to state that a set is returned, not a list. This method is not used yet, so I didn't file a bug for this. Change-Id: I83fbce07936fea2bc936441c5c6594f65da443a7 --- nova/objects/base.py | 2 +- nova/objects/instance.py | 1 + nova/tests/objects/test_instance.py | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/nova/objects/base.py b/nova/objects/base.py index 2e0797477..ec1ada6aa 100644 --- a/nova/objects/base.py +++ b/nova/objects/base.py @@ -311,7 +311,7 @@ class NovaObject(object): raise NotImplementedError('Cannot save anything in the base class') def obj_what_changed(self): - """Returns a list of fields that have been modified.""" + """Returns a set of fields that have been modified.""" return self._changed_fields def obj_reset_changes(self, fields=None): diff --git a/nova/objects/instance.py b/nova/objects/instance.py index aec6fe968..cd08c4c4f 100644 --- a/nova/objects/instance.py +++ b/nova/objects/instance.py @@ -256,6 +256,7 @@ class Instance(base.NovaObject): if (hasattr(self, base.get_attrname(field)) and self[field] != current[field]): self[field] = current[field] + self.obj_reset_changes() def obj_load_attr(self, attrname): extra = [] diff --git a/nova/tests/objects/test_instance.py b/nova/tests/objects/test_instance.py index a9238a924..efd0bcdf9 100644 --- a/nova/tests/objects/test_instance.py +++ b/nova/tests/objects/test_instance.py @@ -163,6 +163,7 @@ class _TestInstanceObject(object): inst.refresh() self.assertEqual(inst.host, 'new-host') self.assertRemotes() + self.assertEqual(set([]), inst.obj_what_changed()) def test_save(self): ctxt = context.get_admin_context() -- cgit