fix(strict_schema): guard resolve_ref against missing $ref path#3552
Closed
devteamaegis wants to merge 1 commit into
Closed
fix(strict_schema): guard resolve_ref against missing $ref path#3552devteamaegis wants to merge 1 commit into
devteamaegis wants to merge 1 commit into
Conversation
…e = resolved[key]` Replace bare subscript with try/except KeyError that raises a descriptive ValueError when a $ref points to a missing path in the schema, consistent with the existing ValueError for malformed $ref formats.
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.
What's broken
resolve_refinstrict_schema.pydoes a bareresolved[key]subscript with noKeyErrorguard. Whenensure_strict_json_schemaencounters a property with both a$refand a sibling key (e.g.description), it unravels the ref viaresolve_ref. If the referenced path does not exist — e.g. a hand-craftedparams_json_schemawith a$refbut no$defssection — the loop crashes withKeyError: '$defs'instead of a clear diagnostic. The adjacent code already raisesValueErrorfor malformed$refstrings, but a well-formatted ref pointing to a missing path was unguarded.Why it happens
The
for key in pathloop inresolve_ref(line 158–163) subscriptsresolved[key]directly without catchingKeyError.Fix
Wrapped the subscript in a
try/except KeyErrorthat re-raises asValueErrornaming the missing key and the offending$ref, consistent with the existing error handling pattern in the same function.Test
test_resolve_ref_raises_valueerror_for_missing_pathintests/test_strict_schema.pycallsensure_strict_json_schemawith a schema that has a$ref+descriptionproperty but no$defs, and asserts aValueErroris raised with the expected message.Fixes #3551