property setter is not called when setting a field

Bug #1821619 reported by Balazs Gibizer
6
This bug affects 1 person
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 TestObjectWithProperties(test.TestCase):
    @base.VersionedObjectRegistry.register
    class MyObj(base.VersionedObject):
        VERSION = '1.0'
        fields = {'foo': fields.Field(fields.Integer())}

        @property
        def foo(self):
            return self.foo

        @foo.setter
        def foo(self, value):
            if value < 0:
                raise ValueError()
            self.foo = value

    def test_setter(self):
        obj = MyObj()
        try:
            obj.foo = -1
        except ValueError:
            pass
        else:
            self.fail('ValueError are expected')

description: updated
Revision history for this message
Balazs Gibizer (balazs-gibizer) wrote :

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.versionedobjects/blob/ca9dec1ad6d050b7c8a9d3e1b05700e08ee80db5/oslo_versionedobjects/base.py#L96

Revision history for this message
Balazs Gibizer (balazs-gibizer) wrote :

Meanwhile the original use case in nova also found to be non usable [1] do to further issues how OVO handles object invariant. For example OVO implements deepcopy by first instantiating a new object then copying fields one by one.

[1] https://review.openstack.org/#/c/647396/5//COMMIT_MSG@30

Changed in oslo.versionedobjects:
status: New → Opinion
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.