Validate property values on export to prevent writing invalid files#832
Open
ehennestad wants to merge 7 commits into
Open
Validate property values on export to prevent writing invalid files#832ehennestad wants to merge 7 commits into
ehennestad wants to merge 7 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## fix-scalar-datetime-export #832 +/- ##
=============================================================
Coverage ? 95.32%
=============================================================
Files ? 219
Lines ? 7682
Branches ? 0
=============================================================
Hits ? 7323
Misses ? 359
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
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
MatNWB validates property values in property
setmethod when objects are constructed, butexportdoes not re-validate them before writing to file. This was sufficient while the only way to populate a property was through its (strict) setter.PR #822 introduced permissive reads for
DynamicTablecolumn names, and the broader read-validation work in #776 will extend permissive reads to other schema checks (data type, shape, neurodata type, fixed/constant attribute values). Once a value can enter an object without passing strict validation, nothing stops it from being written back out to a new, non-conforming file.This PR adds an export-time guard so a value that bypassed strict validation cannot be written to a new file.
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