Validate property values on export to prevent writing invalid files#832
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #832 +/- ##
=======================================
Coverage 95.28% 95.29%
=======================================
Files 219 219
Lines 7702 7737 +35
=======================================
+ Hits 7339 7373 +34
- Misses 363 364 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
- A scalar datetime was wrapped in a cell. This is an unnecessary mutation which is removed here - A cell array of datetimes where all values either have TimeZone info or do not, is now output as a datetime array.
Undo non-scalar cell array to datetime array. Mutating outputs should be minimised
Add test ensuring scalar dataset is NOT read as datastub Add test checking that scalar datetime is exported to a scalar dataspace
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
… test Co-authored-by: ehennestad <17237719+ehennestad@users.noreply.github.com>
484da14 to
a35e1c4
Compare
This was referenced Jun 25, 2026
Contributor
|
I don't understand the type of invalid workflow you are trying to prevent |
bendichter
approved these changes
Jun 30, 2026
Update reference to the validation context function (was renamed)
…urodataWithoutBorders/matnwb into validate-properties-on-export
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
Background
MatNWB
v2.9.0fixed some validation bugs rendering existing NWB files unreadable because of strict validation on read. In issue #776, the consensus is to relax validation on read, showing warnings instead of errors if validation fails.PR #836 (merged) and PR #830 is ongoing work to support that.
Problem
However, relaxing validation on read creates a new problem. MatNWB currently validates property values only on construction and modification, not on export. If users are allowed to read an NWB file with invalid values, they are also free to re-export those invalid values to new NWB files.
Solution
This PR adds an export-time guard, ensuring that all properties are re-validated on file export.
Changes
types.untyped.MetaClass/validateProperties, invoked inexportalongside the existing required-property and custom-constraint checks. For each set property that has a generatedvalidate_<prop>method, it re-runs the validator and discards the result, so there are no setter side effects such as type coercion or column-name syncing. If the value is invalid it raisesNWB:Export:InvalidPropertyValue, including the property name and file location, and preserves the original validator error as a cause.exportwrites.Relationship to other work
This is the write-side counterpart to the read-side permissiveness in #776 — read lenient (warn, keep value), write strict (error). It generalizes the pattern already used for
DynamicTable(checkConfigvia the custom-constraint path) to all property validators. Its user-visible effect lands together with #776, so this is best reviewed and merged alongside that work.How to test
tests.unit.types.MetaClassValidatePropertiesTestexercises the guard with a smallMetaClasstest double: an invalid property value raisesNWB:Export:InvalidPropertyValuewith the property name, location, and original cause; an unset (empty) property is skipped; a valid value passes.Checklist
fix #XXwhereXXis the issue number?🤖 Generated with Claude Code