property setter is not called when setting a field
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
oslo.versionedobjects |
Opinion
|
Undecided
|
Unassigned |
Bug Description
The below testcase fails. I tried also the rename the getter and setter to 'foo_' to avoid clashing with an existing setter in the base class.
This currently prevent to trigger some additional calculation on a Nova ovo when certain fields are updated.
class TestObjectWithP
@base.
class MyObj(base.
VERSION = '1.0'
fields = {'foo': fields.
@property
def foo(self):
return self.foo
@foo.setter
def foo(self, value):
if value < 0:
def test_setter(self):
obj = MyObj()
try:
obj.foo = -1
except ValueError:
pass
else:
description: | updated |
The reason of the reported behavior is the way OVO generates properties for each OVO field automatically at [1].
So when an class defines its own property to a field, OVO register decorator will overwrite that property with a generated property.
Technically the OVO decorator could detect if there are already a property defined for a field but without the cooperation from the implementer of that property OVO cannot hook the two properties into the call chain to ensure both the manually implemented and the OVO generated properties are called during the field access.
[1] https:/ /github. com/openstack/ oslo.versionedo bjects/ blob/ca9dec1ad6 d050b7c8a9d3e1b 05700e08ee80db5 /oslo_versioned objects/ base.py# L96