From 48a48c9163e2df9e0bd58d504893c94a2f54fde1 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Thu, 26 Feb 2015 12:30:18 -0600 Subject: [PATCH] Allow user to set a prop back to default This allows the attribute/prop to be set while still bypassing the type conversion introduced in I106c9c54f57596cb2e12e8bbb5cd380867be876b. Closes-bug: 1425996 Change-Id: I388b671b1574109c767724a0be17ce60034036be --- openstack/resource.py | 6 ++---- openstack/tests/test_resource.py | 9 +++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/openstack/resource.py b/openstack/resource.py index be4ec2af..86446cdf 100644 --- a/openstack/resource.py +++ b/openstack/resource.py @@ -122,10 +122,8 @@ class prop(object): return value def __set__(self, instance, value): - if value == self.default: - return - - if self.type and not isinstance(value, self.type): + if (self.type and not isinstance(value, self.type) and + value != self.default): if issubclass(self.type, Resource): if isinstance(value, six.string_types): value = self.type({"id": value}) diff --git a/openstack/tests/test_resource.py b/openstack/tests/test_resource.py index fcf76725..cfd18e35 100644 --- a/openstack/tests/test_resource.py +++ b/openstack/tests/test_resource.py @@ -96,6 +96,15 @@ class PropTests(base.TestCase): t.attr2 = new_default self.assertIs(t.attr2, new_default) + not_default = 'not default' + t2 = Test({'attr2': not_default}) + self.assertEqual(t2.attr2, not_default) + + # Assert that if the default is passed in, it overrides the previously + # set value (bug #1425996) + t2.attr2 = new_default + self.assertEqual(t2.attr2, new_default) + def test_get_without_instance(self): self.assertIsNone(FakeResource.name)