Skip to content

Stop fact walks at mapped refs in one ref-follow step - #6775

Merged
Koudai Aono (koxudaxi) merged 1 commit into
mainfrom
refactor-mapped-ref-step
Nov 13, 2026
Merged

Koudai Aono (koxudaxi) merged 1 commit into
mainfrom
refactor-mapped-ref-step

Conversation

@koxudaxi

@koxudaxi Koudai Aono (koxudaxi) commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of schema references during validation and generation, including consistent cycle detection and more reliable traversal of nested references.

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The change centralizes $ref target lookup, external-reference filtering, and visited-target tracking in _schema_refs. Schema validators and other parser traversals now use those helpers. Union-tag traversal uses immutable visited-target sets.

Changes: Reference traversal

Layer / File(s) Summary
Centralize reference lookup
src/datamodel_code_generator/parser/_schema_refs.py, src/datamodel_code_generator/parser/_lightweight_types.py
_schema_refs now exports helpers for unmapped reference lookup and visited-target tracking. The duplicate unvisited_ref_target helper is removed from _lightweight_types.
Update schema validators
src/datamodel_code_generator/parser/_schema_validators.py
Property-count, scoped-schema, container-acceptance, and uniqueItems traversals use the shared unmapped-reference helper.
Update other parser traversals
src/datamodel_code_generator/parser/_all_of_values.py, src/datamodel_code_generator/parser/_union_tags.py, src/datamodel_code_generator/parser/jsonschema.py
AllOf, union-tag, and JSON Schema traversals use the shared reference helpers. Union-tag traversal uses immutable visited-target sets.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related PRs

Merge Risk: Minimal · up to ad730

This is a refactor that consolidates reference lookup and cycle tracking. No actionable merge-blocking risk is evident from the supplied context.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Stop fact walks at mapped refs in one ref-follow step" is specific and matches the changeset. The summaries show that unmapped_ref_target in _schema_refs.py now returns None for externally …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Stop fact walks at mapped refs in one ref-follow step" is specific and matches the changeset. The summaries show that unmapped_ref_target in _schema_refs.py now returns None for externally mapped references, and that the callers in _schema_validators.py, _union_tags.py, and jsonschema.py route reference resolution through it. The title names the main behavior change: mapped references stop the walk in a single step. The title uses terms from the commit message and does not describe unrelated work. Some terms, such as "fact walks" and "ref-follow step", are internal jargon, so a reader outside the parser code may need the description to follow it.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between f16595d and ad730f3.

Files selected for processing: 6

  • src/datamodel_code_generator/parser/_all_of_values.py
  • src/datamodel_code_generator/parser/_lightweight_types.py
  • src/datamodel_code_generator/parser/_schema_refs.py
  • src/datamodel_code_generator/parser/_schema_validators.py
  • src/datamodel_code_generator/parser/_union_tags.py
  • src/datamodel_code_generator/parser/jsonschema.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@koxudaxi
Koudai Aono (koxudaxi) marked this pull request as ready for review November 12, 2026 20:39
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T20:41:02.969153Z ad730f3 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown
Contributor

@codspeed

codspeed Bot commented Nov 12, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

✅ 53 untouched benchmarks
⏩ 98 skipped benchmarks1


Comparing refactor-mapped-ref-step (ad730f3) with main (f16595d)

Open in CodSpeed

Footnotes

  1. 98 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@koxudaxi
Koudai Aono (koxudaxi) merged commit d591b60 into main Nov 13, 2026
117 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the refactor-mapped-ref-step branch November 13, 2026 05:05
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: This PR is an internal refactor of private parser modules. The helper unvisited_ref_target moves from the private _lightweight_types module to the private _schema_refs module. The unmapped_ref_target helper moves from _schema_validators to _schema_refs. Inline code that checked external ref mappings and visited nodes in _schema_validators, _union_tags and jsonschema is replaced with calls to the shared unmapped_ref_target helper, which keeps the same order of checks: a mapped ref is skipped, a visited node is skipped, otherwise the target is loaded. The seen_refs parameters of private union tag helpers and of the private _get_single_literal_value method change from an optional mutable set to a frozenset. All affected names are in underscore-prefixed modules or are private methods, and the analysis context lists no public Python names, CLI options, presets or experimental features affected. The behaviour diff gate reports only both-fail cells, with no accepted or violation cells, so default generated output is unchanged. There are no changes to templates, Python version support or error reporting.


This analysis was produced by the release draft workflow

@github-actions

Copy link
Copy Markdown
Contributor

🎉 Released in 0.96.0

This PR is now available in the latest release. See the release notes for details.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant