@@ -73,12 +73,14 @@ def __init__(self, document_type: Union[str, dict, "ndi_document"] = "base", **k
7373 if isinstance (document_type , dict ):
7474 # Loading from existing properties
7575 self ._document_properties = deepcopy (document_type )
76+ self ._normalize_depends_on ()
7677 elif isinstance (document_type , ndi_document ):
7778 # Copy from another ndi_document
7879 self ._document_properties = deepcopy (document_type .document_properties )
7980 elif DIDDocument is not None and isinstance (document_type , DIDDocument ):
8081 # Convert from DIDDocument
8182 self ._document_properties = deepcopy (document_type .document_properties )
83+ self ._normalize_depends_on ()
8284 else :
8385 # Create new from schema
8486 self ._document_properties = self .read_blank_definition (document_type )
@@ -92,6 +94,27 @@ def __init__(self, document_type: Union[str, dict, "ndi_document"] = "base", **k
9294 for key , value in kwargs .items ():
9395 self ._set_nested_property (key , value )
9496
97+ def _normalize_depends_on (self ):
98+ """Ensure depends_on and files.file_info are always lists.
99+
100+ MATLAB's jsonencode converts single-element cell arrays to scalars,
101+ so documents downloaded from the cloud (or created by MATLAB) may
102+ have ``depends_on`` or ``files.file_info`` as a bare dict instead
103+ of a list. Normalizing here guarantees that downstream code
104+ (including DID-python's ``doc_to_sql`` / ``_serialize_depends_on``
105+ and all NDI code that iterates over ``file_info``) always sees
106+ a list.
107+ """
108+ dep = self ._document_properties .get ("depends_on" )
109+ if isinstance (dep , dict ):
110+ self ._document_properties ["depends_on" ] = [dep ]
111+
112+ files = self ._document_properties .get ("files" )
113+ if isinstance (files , dict ):
114+ fi = files .get ("file_info" )
115+ if isinstance (fi , dict ):
116+ files ["file_info" ] = [fi ]
117+
95118 @property
96119 def document_properties (self ) -> dict :
97120 """The document's properties as a nested dictionary."""
0 commit comments