Skip to content

Do not fill an absent named link with links of a matching type - #1598

Open
bendichter wants to merge 2 commits into
devfrom
fix-missing-named-link
Open

bendichter wants to merge 2 commits into
devfrom
fix-missing-named-link

Conversation

@bendichter

Copy link
Copy Markdown
Contributor

Motivation

Fix #1595.

On read, ObjectMapper.__get_subspec_values assigns a named link from the group's link of that name. If the file has no link with that name, the else branch also ran for named specs and matched the group's other links by target_type. Since #1481, subtypes match too, so an optional named link whose target type is a common base type got every other link in the group as a list. Construction then failed.

DANDI dandiset 001878 hits this. Its EthogramBouts (ndx-ethogram) declares optional links source (target NWBDataInterface), source_pose, source_video, observation_intervals and ethogram. The file sets all of them except source:

ConstructError: ... "Could not construct EthogramBouts object due to: CustomClassGenerator.set_init.<locals>.__init__: incorrect type for 'source' (got 'list', expected 'NWBDataInterface')"

This PR matches links by type only for unnamed link specs (else: → elif subspec.name is None:). A named link that's absent from the file is left unset.

How to test the behavior?

pytest tests/unit/build_tests/test_io_map.py -k MissingNamedLink

The new test fails on dev (source is set to the other link's target) and passes with this change. The full unit suite shows no new failures. The DANDI file (https://dandiarchive.s3.amazonaws.com/blobs/eaa/b5c/eaab5c37-7a7f-4b65-864d-f2986df5d64e) reads with pynwb 4.2.0 on this branch.

Checklist

  • Did you update CHANGELOG.md with your changes?
  • Does the PR clearly describe the problem and the solution?
  • Have you reviewed our Contributing Guide?
  • Does the PR use "Fix #XXX" notation to tell GitHub to close the relevant issue numbered XXX when the PR is merged?

🤖 Generated with Claude Code

Benjamin Dichter and others added 2 commits October 11, 2026 10:28
On read, a link spec with a name that is absent from the file fell through
to matching the group's links by target type. Since subtypes match (#1481),
an optional link whose target_type is a common base type received a list
of every link in the group, and construction failed. Match links by type
only for unnamed link specs.

Fix #1595

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (a7e0ec3) to head (080352c).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1598      +/-   ##
==========================================
- Coverage   93.17%   93.16%   -0.01%     
==========================================
  Files          41       41              
  Lines       10304    10305       +1     
  Branches     2132     2133       +1     
==========================================
  Hits         9601     9601              
  Misses        423      423              
- Partials      280      281       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

[Bug]: A missing optional named link is filled with other links of a matching type on read

1 participant