ConfigDB2: Potential spurious change of default values

Hi @clemenci,

not sure if this qualifies as bug or as feature but it's at least a dangerous pitfall.

Let's assume myAlg has a property that is a ToolHandleArray (or any other non-trivial data type). Then myAlg.ToolHandleArray.append(aNewTool) will update the default of the class, eg myAlg._descriptors["ToolHandleArray"].default. That happens because of the __get__ method of the Property class (see here. It returns a reference to the default instance, and append (or +=) will act on the default instance.

If there are a properly-implemented semantics classes for all possible property-types (that specify a default-method) the problem goes away because this particular line will not be executed any longer. I imagine this is what you had in mind when you coded this part.

I see two possible ways to safeguard against this nasty pitfall:

  • Deep-copy the default property in the return statement of Property.__get__
  • Implement a default(self, value) method in PropertySemantics that deep-copies value before returning it.

I think the first method would be safer.

  • Walter
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information