diff --git a/nomad/metainfo/metainfo.py b/nomad/metainfo/metainfo.py index b659239c55615b1cae221e7b5664d39c8b1210fc..838ea257463c37cf98301fc136c57999cbc5c6a7 100644 --- a/nomad/metainfo/metainfo.py +++ b/nomad/metainfo/metainfo.py @@ -476,6 +476,19 @@ class Reference: def _proxy_type(self): return self._definition.type if self._definition else SectionReference() + def _check_shape(self, value): + dimension: int = 0 + target = value + while isinstance(target, list): + dimension += 1 + # assuming consistent data + target = target[0] + + if dimension != len(self._definition.shape): + raise ValueError(f'Invalid shape for {value}.') + + return value + def serialize_self(self, section): if (context := section.m_root().m_context) is not None: try: @@ -540,7 +553,7 @@ class Reference: return self._normalize_impl(section, _v) - return _convert(value) + return self._check_shape(_convert(value)) def _serialize_impl(self, section, value): return _append_id(