Normalize bare dict depends_on to list for MATLAB compatibility#47
Merged
Conversation
MATLAB's jsonencode converts single-element cell arrays to scalars, so
documents downloaded from the cloud (or created by MATLAB) may have
depends_on as a bare dict {"name": "x", "value": "y"} instead of a
list [{"name": "x", "value": "y"}]. DID-python's _serialize_depends_on
rejects non-list depends_on and returns "", leaving field 6 in doc_data
blank.
Normalize depends_on to always be a list in ndi_document.__init__ when
loading from a dict or DIDDocument, so downstream code always sees the
correct format.
https://claude.ai/code/session_0169wc3G2LGv6cq86MYzo7dp
MATLAB's jsonencode also converts single-element file_info arrays to bare dicts. Many places in NDI iterate over file_info assuming a list, which would silently iterate over dict keys instead of file entries. Extend the existing _normalize_depends_on to also wrap a bare dict files.file_info into a single-element list. https://claude.ai/code/session_0169wc3G2LGv6cq86MYzo7dp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes handling of
depends_onfields that are stored as bare dictionaries instead of lists. This occurs when documents are created by MATLAB (which converts single-element cell arrays to scalars viajsonencode) or downloaded from the cloud.Key Changes
_normalize_depends_on()method tondi_documentthat converts bare dictdepends_onto a list during initialization. This ensures downstream code (including DID-python's serialization) always sees a consistent list format._normalize_depends_on()in two initialization paths:depends_onis normalized to a list in document propertiesdepends_onsearchImplementation Details
The normalization is applied early in the document initialization process, guaranteeing that all downstream code works with a consistent list format. This approach is non-breaking since it only affects the internal representation and makes the behavior consistent regardless of the source of the document.
https://claude.ai/code/session_0169wc3G2LGv6cq86MYzo7dp