Skip to content

RelationshipElement.first/second optional in spec but required in AnnotatedRelationshipElement and both serializers #559

@s-heppner

Description

@s-heppner

According to AAS spec 3.1.2 (IDTA-01001), RelationshipElement.first and .second have multiplicity 0..1. Both the JSON schema
(RelationshipElement_abstract — no required array) and the XML schema (relationshipElement group — minOccurs="0") reflect this.

RelationshipElement.__init__ was updated to match (Optional[base.Reference] = None), but three places were not:

  • AnnotatedRelationshipElement.__init__ in basyx/aas/model/submodel.py still declares first and second as required positional arguments, contradicting its parent class and the spec.
  • _construct_relationship_element and _construct_annotated_relationship_element in basyx/aas/adapter/json/json_deserialization.py currently call _get_ts(dct, 'first'/'second', dict), which is a mandatory getter, causing a KeyError when either field is absent in the JSON input.
  • _construct_relationship_element_internal in basyx/aas/adapter/xml/xml_deserialization.py currently calls _child_construct_mandatory(element, NS_AAS + "first"/"second", ...) which would likewise raise on absent fields.

Suggested fixes:

  • submodel.py: update AnnotatedRelationshipElement.__init__ to first: Optional[base.Reference] = None, second: Optional[...] = None.
  • json_deserialization.py: replace the mandatory _get_ts calls with an optional pattern, e.g. cls._construct_reference(_get_ts(dct, 'first', dict)) if 'first' in dct else None.
  • xml_deserialization.py: replace _child_construct_mandatory with _failsafe_construct(element.find(NS_AAS + "first"), cls.construct_reference, cls.failsafe).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsdkSomething to do with the `sdk` package

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions