Custom Component with Object Custom Prop and setter doesn't have default value

yes for all other property types except "object" the properties dict will include the values from the designer (or the default value if no value was set).

But for "object" types the properties dict will not include that item.
Mostly because "object" types are expected to be set at runtime.
(You’ll see this description in the designer next that property)

The place where we call the setters is in the init_components method.
And since the "object" property is not included in the properties dict, the "object" property is not set during the init_components method.

I agree that this might be considered incorrect behaviour. And perhaps a None value would have been better than no value.

But since this is the way it’s always been, it’s difficult to change this behaviour.
Any custom setter, that is overriding a property that is of type object, may never have handled a None value before, because "object" properties have always been “set at runtime”.


So unfortunately the right way to handle this is some defensive programming. Your custom property getters should work if the setter were never called.


We have internally talked about APIs that would help with the boiler plate here. But they’re difficult to get right. Something that allows you to do something when a property is set, without having to deal with the boiler plate of assigning the value to a private attribute.

class CustomComponent(CustomComponentTemplate):

    @post_setter("my_prop")
    def my_prop_post_setter(self):
         ...

You can actually create something that works quite well for the above api idea.
Happy to share these if they’re of interest.

here’s a related thread