Validate a name-matching builder against its named spec instead of a wildcard sibling - #1556
Validate a name-matching builder against its named spec instead of a wildcard sibling#1556adityasingh2400 wants to merge 3 commits into
Conversation
…rd sibling A builder whose name matches an optional named sub-spec was dropped by the type filter in SpecMatcher._best_matching_spec and absorbed by a sibling wildcard spec of a parent type, so the type mismatch validated clean. _filter_by_name now treats an explicit name match as authoritative and discards the unnamed candidates. A builder that matches a named spec by name but not by type is recorded and reported as an IncorrectDataType error, which is needed because an optional spec with no assigned builders reports nothing. Fix hdmf-dev#1554
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #1556 +/- ##
==========================================
- Coverage 93.15% 93.13% -0.03%
==========================================
Files 41 41
Lines 10245 10263 +18
Branches 2119 2124 +5
==========================================
+ Hits 9544 9558 +14
- Misses 422 424 +2
- Partials 279 281 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Flagging a problem with this PR that I do not think I should decide on my own.
The first two are exactly the shape this PR is meant to catch, and that is the awkward part. In both, the builder carries the parent type where the current schema names a child type, So I do not think there is a way to keep the #1554 fix and keep these files validating clean. They are the same situation. The difference is only that one is a schema bug and the others are files written before the schema was refined, and the validator has no way to tell those apart from the builder and spec alone. That makes this a policy question rather than something I can patch around, so I would rather ask than guess:
The third error looks different from the other two and I could not fully account for it. There the builder holds Happy to implement either direction once you tell me which one you want. |
|
Hi @adityasingh2400, thanks for the contribution! The PR is a good start, and I will respond to your comment in a follow-up comment. In the age of coding agents, we want to be careful about how we handle contributions and are starting to implement steps to ensure that all changes are properly reviewed and validated. Your account opened 133 pull requests today across 57 repositories. Based on this volume (and tells in the PR text), these PRs appear to be largely generated and submitted by an agent. We are not opposed to AI-assisted contributions. Most of my own recent PRs and issues here are co-authored by a coding agent. But, we require that every change is accountable to two humans, an author and a reviewer. Autonomous PRs without human author oversight shift the entire review burden and accountability onto maintainers. What is your review process? Could you let me know how much you, the human, reviewed the code changes here, and how much you understand them and their impact on the codebase and users? Same for your other PRs (e.g., #1557, NeurodataWithoutBorders/pynwb#2240, NeurodataWithoutBorders/pynwb#2239, which I will also review). If they were submitted autonomously without human review, please say so. Thank you. |
Motivation
Fix #1554
When a group spec has an optional named sub-spec with a data type (
name: col1,data_type_inc: TypedVector,quantity: '?') next to a sibling wildcard sub-spec of the parent type (data_type_inc: BaseVector,quantity: '*'), a builder namedcol1whose type is onlyBaseVectorwas silently absorbed by the wildcard spec and validated clean.The root cause is the order of the two filters in
SpecMatcher._best_matching_spec._filter_by_namekept both the namedcol1spec and the unnamed wildcard, then_filter_by_typedropped the named spec because the builder's type is not a subtype ofTypedVector. The name match was therefore discarded rather than treated as authoritative, and the builder fell through to the wildcard. The named spec ended up with zero matched builders, and since it is optional,__validate_presence_and_quantityreported nothing. Enforcement of a named typed sub-spec depended entirely on whether it happened to be required.This is the mechanism behind the NWB case in the issue, where an
EventsTablewhosedurationcolumn is a plainVectorDatarather than aDurationVectorDatavalidates with no errors.The fix
_filter_by_namenow short-circuits, which is the option suggested in the issue. If any candidate spec names the builder explicitly, only those candidates are kept and the unnamed ones are dropped, so a name-matching builder can no longer fall through to a wildcard sibling.That alone would leave the builder simply unmatched, which is still silent for an optional spec, so
SpecMatcheralso records builders that matched a named spec by name but not by type.GroupValidatorreports each of those as anIncorrectDataTypeerror, an error class that already existed for reference-target type mismatches. A required named spec now reports the type mismatch directly instead of the indirectMissingDataTypeit produced before.How to test the behavior?
TestNamedSubspecTakesPrecedenceOverWildcardintests/unit/validator_tests/test_validate.pycovers this. With the source change reverted and the test kept, the two mismatch cases fail:With the fix applied, all 5 pass, and the full suite is clean:
1869 passed, 118 skipped, 1 xfailed, 919 subtests passed.Checklist
CHANGELOG.mdwith your changes?