fix: guard attrLookup lookup against unmapped attribute types - #124
Open
CptOrange16 wants to merge 1 commit into
Open
CptOrange16 wants to merge 1 commit into
CptOrange16 wants to merge 1 commit into
Conversation
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.
Problem
Related to issue #123
chkAttributecrashes with an uncaughtKeyErrorwhen a standard CFattribute (e.g.
comment,flag_meanings) has a value that netCDF4reads back as a Python
listrather than a single string or numericvalue.
Root cause
In the type-detection block, if a value doesn't match any of the
expected types (string, numeric,
ndarray,None),attrTypeis leftas the raw Python type object (e.g.
<class 'list'>) instead of beingmapped to a reportable type code:
That unmapped value then reaches:
which crashes the entire checker run instead of reporting a normal
validation error.
Fix
Use
.get(attrType, str(attrType))instead of a direct[attrType]lookup, so an unrecognized type degrades to a readable error message
(e.g.
got '<class 'list'>' type) instead of raising.Test added
tests/test_chkattribute_list_type_crash.pybuilds a minimalin-memory netCDF file with a list-valued
commentattribute andasserts:
checker.checker(...)completes without raising.ERRORis recorded against the offending attribute.Verified: fails with the original
KeyErroronmaster, passes afterthis patch.
Scope note
A list-valued
flag_meaningsattribute triggers a separate crashfurther downstream, in
chkFlags->extendedBlankSeparatedList(which also assumes a string and calls
re.matchdirectly on thevalue). Same class of bug, different function — deliberately left out
of this PR to keep it focused. Happy to open a follow-up if useful.