Skip to content

Normalize bare dict depends_on to list for MATLAB compatibility#47

Merged
stevevanhooser merged 2 commits into
mainfrom
claude/fix-sqlite-dependencies-6hZou
Mar 22, 2026
Merged

Normalize bare dict depends_on to list for MATLAB compatibility#47
stevevanhooser merged 2 commits into
mainfrom
claude/fix-sqlite-dependencies-6hZou

Conversation

@stevevanhooser

Copy link
Copy Markdown
Contributor

Summary

This PR fixes handling of depends_on fields 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 via jsonencode) or downloaded from the cloud.

Key Changes

  • Document normalization: Added _normalize_depends_on() method to ndi_document that converts bare dict depends_on to a list during initialization. This ensures downstream code (including DID-python's serialization) always sees a consistent list format.
  • Applied normalization: Called _normalize_depends_on() in two initialization paths:
    • When loading from existing properties (dict input)
    • When converting from DIDDocument
  • Test coverage: Added comprehensive tests to verify:
    • Bare dict depends_on is normalized to a list in document properties
    • Normalized documents can be queried correctly via depends_on search
    • Dependency values are accessible after normalization

Implementation 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

claude added 2 commits March 22, 2026 19:04
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
@stevevanhooser stevevanhooser merged commit 4d8ebf1 into main Mar 22, 2026
10 checks passed
@stevevanhooser stevevanhooser deleted the claude/fix-sqlite-dependencies-6hZou branch March 22, 2026 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants