Skip to content

[codex] Preserve legacy device model names on read#2186

Draft
bendichter wants to merge 2 commits intodevfrom
codex-preserve-legacy-device-model-name
Draft

[codex] Preserve legacy device model names on read#2186
bendichter wants to merge 2 commits intodevfrom
codex-preserve-legacy-device-model-name

Conversation

@bendichter
Copy link
Copy Markdown
Collaborator

@bendichter bendichter commented Apr 24, 2026

fix #2185

Summary

Fixes the read-time remapping path for legacy files where Device.model is stored as a string containing characters such as / or :.

Instead of sanitizing the legacy value, PyNWB now constructs the remapped DeviceModel in HDMF construct mode, matching the normal file-read construction path. This preserves the original model name in memory while still avoiding the user-facing name validation that is meant to prevent invalid newly-created container names.

Root cause

DeviceMapper.model_carg manually created a DeviceModel with DeviceModel(...). That bypassed HDMF's usual read-time in_construct_mode=True path, so AbstractContainer.__init__ rejected legacy model strings containing / or :.

Validation

  • PYTHONPATH=src .tox/test-py312-pinned/bin/python -m pytest tests/unit/test_device.py -q
  • PYTHONPATH=src .tox/test-py312-pinned/bin/python -m pytest tests/back_compat/test_read.py::TestReadOldVersions::test_read_device_model_str_attribute -q
  • Earlier full pinned tox run passed: python -m tox -e test-py312-pinned -- tests/unit/test_device.py (683 tests - OK)

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.11%. Comparing base (e92a51b) to head (189a603).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #2186   +/-   ##
=======================================
  Coverage   95.10%   95.11%           
=======================================
  Files          29       29           
  Lines        2943     2948    +5     
  Branches      443      443           
=======================================
+ Hits         2799     2804    +5     
  Misses         86       86           
  Partials       58       58           
Flag Coverage Δ
integration 72.89% <100.00%> (+0.04%) ⬆️
unit 85.54% <100.00%> (+0.19%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

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]: Loading nwbs created with older pynwb version fails due to '/' or ':' in Device.model name

1 participant