You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Referable.update_from() patches the self object with the other object by iterating over the attributes of the other objects using the python built-in vars(). vars() only iterates over an objects attributes, not properties e.g. getter/setter functions. The id_short attribute of Referable is a property, which performs additional checks when setting the id_short, such as checking for uniqueness within the namespace by searching the objects contained in the parent object. The actual value of the id_short is stored in the protected attribute _id_short.
Since _id_short is an attribute and id_short is a property, the vars() built-in returns the _id_short attribute instead of the id_short property, which causes update_from() to update the _id_short directly, skipping the setter function and thus the uniqueness check.
This is also the case for the semantic_id property of HasSemantics, which also checks for uniqueness.
A solution proposed by @s-heppner and Michael Thies is to add dictionaries to each class, mapping the protected attributes to the respective property. These dictionaries would then be searched by update_from(), which can then set the property instead of the attribute.
Referable.update_from()
patches theself
object with theother
object by iterating over the attributes of theother
objects using the python built-invars()
.vars()
only iterates over an objects attributes, not properties e.g. getter/setter functions. Theid_short
attribute ofReferable
is a property, which performs additional checks when setting theid_short
, such as checking for uniqueness within the namespace by searching the objects contained in theparent
object. The actual value of theid_short
is stored in the protected attribute_id_short
.Since
_id_short
is an attribute andid_short
is a property, thevars()
built-in returns the_id_short
attribute instead of theid_short
property, which causesupdate_from()
to update the_id_short
directly, skipping the setter function and thus the uniqueness check.This is also the case for the
semantic_id
property ofHasSemantics
, which also checks for uniqueness.A solution proposed by @s-heppner and Michael Thies is to add dictionaries to each class, mapping the protected attributes to the respective property. These dictionaries would then be searched by
update_from()
, which can then set the property instead of the attribute.Transferred from: https://git.rwth-aachen.de/acplt/pyi40aas/-/issues/133
The text was updated successfully, but these errors were encountered: