fix: guard against AttributeError when node lacks id in error messages#929
Open
armorbreak001 wants to merge 1 commit intoyaml:mainfrom
Open
fix: guard against AttributeError when node lacks id in error messages#929armorbreak001 wants to merge 1 commit intoyaml:mainfrom
armorbreak001 wants to merge 1 commit intoyaml:mainfrom
Conversation
…ror messages When construct_scalar/construct_sequence/construct_mapping etc. receive a non-Node object (e.g., None, a plain Python object), the error handler unconditionally accesses node.id which raises AttributeError, masking the original ConstructorError. Use getattr with a repr() fallback so the intended error is always raised.
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.
Summary
Closes #907
When
construct_scalar,construct_sequence,construct_mapping, etc. receive a non-Node object (e.g.,None, a plain Python object), the error handler unconditionally accessesnode.idwhich raisesAttributeError, masking the intendedConstructorError.Changes
Replace direct
node.id/subnode.id/value_node.idaccess in all ConstructorError messages withgetattr(node, 'id', repr(node)). This ensures the descriptive error is always raised regardless of whether the input is a proper Node instance.Details
Affected methods in
lib/yaml/constructor.py:BaseConstructor.construct_scalarBaseConstructor.construct_sequenceBaseConstructor.construct_mappingBaseConstructor.construct_pairsSafeConstructor.flatten_mapping(subnode, value_node)SafeConstructor.construct_yaml_omap(node, subnode)SafeConstructor.construct_yaml_pairs(node, subnode)All 1283 existing tests pass.