Fix JSON schema resolver bug with nested $ref#2187
Fix JSON schema resolver bug with nested $ref#2187Naxin Fang (fangnx) wants to merge 3 commits intomasterfrom
Conversation
|
🎉 All Contributor License Agreements have been signed. Ready to merge. |
There was a problem hiding this comment.
Pull request overview
Fixes JSON Schema validation/transform selection when oneOf/anyOf/allOf branches use $ref and the resolved branch contains further nested $refs, by preserving the correct reference-resolution context during validation.
Changes:
- Update
_validate_subschemasto useresolver.lookup(ref)’s returned resolver when validating resolved subschemas (to support nested$ref). - Add sync unit tests covering
oneOf/anyOf/allOfwith$ref, including deeply nested$refchains under rule execution (field encryption).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/confluent_kafka/schema_registry/common/json_schema.py |
Preserves resolver context when validating a $ref-resolved subschema so nested $ref lookups succeed. |
tests/schema_registry/_sync/test_json_serdes.py |
Adds coverage for union keywords with $ref, including nested and deeply nested reference scenarios under encryption rules. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Robert Yokota (rayokota)
left a comment
There was a problem hiding this comment.
Naxin Fang (@fangnx) , I simplified the validation code a bit. Otherwise LGTM
9965eca
264bb32 to
cbf7305
Compare
Sorry I missed this comment/commit. Let me check your code and update the PR |
|




What
Problem
Two related bugs when using
oneOf/anyOf/allOfwith$refreferences and rule executors:Bug 1:
AttributeError: 'Resolver' object has no attribute 'resolving'oneOfwith$ref+ rule executorreferencing.Resolvertovalidate(resolver=...)but jsonschema expected oldRefResolverAPIBug 2:
PointerToNowhere: 'xxx' does not existoneOfsubschemas contain nested$refs(e.g., Account → PaymentMethod)$ref, we lost resolver context needed for reference resolution for the nested subschemaSolution
Use referencing library's intended pattern - lookup() returns both contents AND resolver:
Checklist
References
JIRA: https://confluentinc.atlassian.net/browse/INC-8778
Test & Review
Add several unit tests to cover oneOf, anyOf, allOf $ref, including the nested schema case
Open questions / Follow-ups