Skip to content

Commit 138ab61

Browse files
committed
Fix SubmodelElementList elements with existing id_shorts
Previously, elements of a `SubmodelElementList` would have their `id_short` overwritten by our reference hack. This now only sets an temporary `id_short`, if the `id_short` does not exist. Furthermore, it only removes the `id_short` when removing the element from the `SubmodelElementList`, if it is one of the generated ones.
1 parent 2091e7c commit 138ab61

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

sdk/basyx/aas/model/submodel.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -731,11 +731,13 @@ def _generate_id_short(self, new: _SE) -> None:
731731
# Generate a unique id_short when a SubmodelElement is added, because children of a SubmodelElementList may not
732732
# have an id_short. The alternative would be making SubmodelElementList a special kind of base.Namespace without
733733
# a unique attribute for child-elements (which contradicts the definition of a Namespace).
734-
new.id_short = "generated_submodel_list_hack_" + uuid.uuid1(clock_seq=self._uuid_seq).hex
735-
self._uuid_seq += 1
734+
if new.id_short is None:
735+
new.id_short = "generated_submodel_list_hack_" + uuid.uuid1(clock_seq=self._uuid_seq).hex
736+
self._uuid_seq += 1
736737

737738
def _unset_id_short(self, old: _SE) -> None:
738-
old.id_short = None
739+
if old.id_short.startswith("generated_submodel_list_hack_"):
740+
old.id_short = None
739741

740742
def _check_constraints(self, new: _SE, existing: Iterable[_SE]) -> None:
741743
# Since the id_short contains randomness, unset it temporarily for pretty and predictable error messages.

0 commit comments

Comments
 (0)