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
This commit is contained in:
@@ -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})
|
||||
|
@@ -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)
|
||||
|
||||
|
Reference in New Issue
Block a user