Repository navigation
Warn when loaded classes are replaced by another schema version - #930
Draft
ehennestad wants to merge 1 commit into
Draft
ehennestad wants to merge 1 commit into
ehennestad wants to merge 1 commit into
Conversation
ehennestad
added this pull request to stack #928
October 4, 2026 11:46
ehennestad
force-pushed
the
warn-on-loaded-version-switch
branch
from
October 4, 2026 19:06
15b019e to
a5a5cc3
Compare
ehennestad
force-pushed
the
warn-on-loaded-version-switch
branch
from
October 5, 2026 06:40
a5a5cc3 to
873dfbd
Compare
…rsion When generateCore, generateExtension or nwbRead replaces the classes of a namespace with another version while MATLAB has classes of that namespace loaded from the same folder, MATLAB redefines the loaded classes without a warning. Objects created earlier then use the new class definitions and lose the values of properties the new version does not define. The type cache now issues NWB:TypeCache:LoadedClassesReplaced in that case, listing each replaced namespace with its previous and new version. Regenerating the same version, or replacing classes that are not loaded, does not warn. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ehennestad
force-pushed
the
warn-on-loaded-version-switch
branch
from
October 6, 2026 18:09
873dfbd to
78fda7a
Compare
This branch has not been deployed
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.
Motivation
Problem — A user who has created NWB objects and then reads a file of another schema version, or calls
generateCorewith another version, gets no sign that the objects they hold have changed. After creating atypes.core.TimeSerieswith 2.11.0 classes and callinggenerateCore("2.7.0"), theTimeSeriesnow uses the 2.7.0 class definition. When the new classes replace the old ones on the path, MATLAB redefines the loaded classes without a warning. The objects lose the values of properties the new version does not define, and nothing reports it.Solution — MatNWB now warns when it replaces classes that are loaded in the session with another version, and lists each namespace with its previous and new version.
What changed
generateCore,generateExtension,nwbInstallExtensionandnwbReadissue the warningNWB:TypeCache:LoadedClassesReplacedwhen they replace a namespace with another version while classes of that namespace are loaded from the same folder.Implementation notes
matnwb.internal.typecache.generateNamespacescompares the version innamespaces/<name>.matof the save folder with the version it is about to put there. When they differ, it checksinmemfor loaded classes oftypes.<namespace>, andwhichto confirm they were loaded from the save folder and not from another folder on the path.Examples
Switching schema version with objects in memory
The snippet creates a
TimeSerieswith the 2.11.0 classes, then switches to 2.7.0.Before — The switch is silent.
timeSeriesnow uses the 2.7.0 class definition.After — A warning lists the namespaces whose loaded classes were replaced, with the previous and new versions.
How to test
Run the snippet above in a fresh MATLAB session. Then run the tests, which check the warning for a small test schema with loaded classes, and that there is no warning for the same version or for classes that are not loaded:
Checklist
fix #XXwhereXXis the issue number?🤖 Generated with Claude Code