Skip to content

Fix JSON schema resolver bug with nested $ref#2187

Closed
Naxin Fang (fangnx) wants to merge 3 commits intomasterfrom
fix/inc-8778/correct-nested-resolver
Closed

Fix JSON schema resolver bug with nested $ref#2187
Naxin Fang (fangnx) wants to merge 3 commits intomasterfrom
fix/inc-8778/correct-nested-resolver

Conversation

@fangnx
Copy link
Copy Markdown
Member

@fangnx Naxin Fang (fangnx) commented Feb 11, 2026

What

Problem

Two related bugs when using oneOf/anyOf/allOf with $ref references and rule executors:

Bug 1: AttributeError: 'Resolver' object has no attribute 'resolving'

Bug 2: PointerToNowhere: 'xxx' does not exist

  • Occurs when oneOf subschemas contain nested $refs (e.g., Account → PaymentMethod)
  • After resolving $ref, we lost resolver context needed for reference resolution for the nested subschema

Solution

Use referencing library's intended pattern - lookup() returns both contents AND resolver:

# Get both contents and context-aware resolver:
lookup_result = resolver.lookup(ref)
subschema = lookup_result.contents
subschema_resolver = lookup_result.resolver  # Maintains context!

# Create validator with proper resolver context
cls = validator_for(subschema)
validator = cls(subschema, registry=registry, _resolver=subschema_resolver)
validator.validate(message)

Checklist

  • Contains customer facing changes? Including API/behavior changes
  • Did you add sufficient unit test and/or integration test coverage for this PR?
    • If not, please explain why it is not required

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

Copilot AI review requested due to automatic review settings February 11, 2026 06:07
@fangnx Naxin Fang (fangnx) requested review from a team as code owners February 11, 2026 06:07
@confluent-cla-assistant
Copy link
Copy Markdown

🎉 All Contributor License Agreements have been signed. Ready to merge.
Please push an empty commit if you would like to re-run the checks to verify CLA status for all contributors.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_subschemas to use resolver.lookup(ref)’s returned resolver when validating resolved subschemas (to support nested $ref).
  • Add sync unit tests covering oneOf/anyOf/allOf with $ref, including deeply nested $ref chains 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.

Comment thread src/confluent_kafka/schema_registry/common/json_schema.py Outdated
Comment thread src/confluent_kafka/schema_registry/common/json_schema.py Outdated
Copy link
Copy Markdown
Member

@rayokota Robert Yokota (rayokota) left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naxin Fang (@fangnx) , I simplified the validation code a bit. Otherwise LGTM

@airlock-confluentinc airlock-confluentinc Bot force-pushed the fix/inc-8778/correct-nested-resolver branch from 264bb32 to cbf7305 Compare February 11, 2026 20:30
@fangnx
Copy link
Copy Markdown
Member Author

Naxin Fang (@fangnx) , I simplified the validation code a bit. Otherwise LGTM

Sorry I missed this comment/commit. Let me check your code and update the PR

@sonarqube-confluent
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants