Skip to content

Make a field required through the store op and read whether a root field is constrained in one place each - #5940

Merged
Koudai Aono (koxudaxi) merged 2 commits into
next11-8from
next11-9
Nov 2, 2026
Merged

Koudai Aono (koxudaxi) merged 2 commits into
next11-8from
next11-9

Conversation

@koxudaxi

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

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes

    • Required fields and existing defaults are handled consistently when generating models from schemas, including inherited fields.
    • Root-field constraints are classified more consistently when generating models.
  • Documentation

    • Architecture documentation now describes root-field constraint classification and how required fields interact with existing defaults.

@koxudaxi
Koudai Aono (koxudaxi) marked this pull request as ready for review November 1, 2026 23:25
@koxudaxi Koudai Aono (koxudaxi) changed the title next11 9 Make a field required through the store op and read whether a root field is constrained in one place each Nov 1, 2026
@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 7b58db2 and c8b8d68.

Files ignored due to path filters: 1
  • docs/llms-full.txt is excluded by none and included by none
Files selected for processing: 9
  • docs/architecture.md
  • scripts/generation_store_allowlist.toml
  • src/datamodel_code_generator/_target_binding.py
  • src/datamodel_code_generator/model/base.py
  • src/datamodel_code_generator/parser/_passes/_shared.py
  • src/datamodel_code_generator/parser/_passes/modules.py
  • src/datamodel_code_generator/parser/_rw_split.py
  • src/datamodel_code_generator/parser/base.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.

Walkthrough

Root-field constraint detection now distinguishes declared constraints from constraints consumed by the field type or direct members. Inherited-field and JSON Schema parsing paths now set required-field state through require_field.

Changes: Root Constraint Detection

Layer / File(s) Summary
Constraint helper and consumers
src/datamodel_code_generator/model/base.py, src/datamodel_code_generator/parser/_passes/_shared.py, src/datamodel_code_generator/parser/_passes/modules.py, src/datamodel_code_generator/_target_binding.py, src/datamodel_code_generator/parser/base.py, docs/architecture.md
The root-field constraint helper moves to model.base and provides declared and with-consumed checks. Its consumers use the declared check where required. The architecture table documents both checks.

Required-Field State

Layer / File(s) Summary
Required-field updates
src/datamodel_code_generator/parser/_rw_split.py, src/datamodel_code_generator/parser/jsonschema.py, scripts/generation_store_allowlist.toml, docs/architecture.md
Inherited-field and JSON Schema parsing paths use require_field to set requiredness and default-handling state. The allowlist entries for direct field-state writes are removed, and the architecture table documents the operation.

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

Change: Refactor

Possibly related PRs

Merge Risk: Minimal · up to c8b8d

No actionable merge-blocking issue is established for these refactors. Mergeability remains subject to normal build and test checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and accurately summarizes both main changes: centralizing required-field updates and root-field constraint checks.
Docstring Coverage Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentati…
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: Docstring Coverage

Explanation

Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 6 functions across 6 files. (1 skipped: 1 unsupported.)

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

LanguageTool
docs/architecture.md

LanguageTool checks are incomplete because the per-file request limit of 5 was reached. Remaining text was skipped; findings from completed checks are retained.

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

@chatgpt-codex-connector

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

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T23:26:59.378935Z c8b8d68 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

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

@codecov

codecov Bot commented Nov 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Nov 1, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 47.53%

2 warnings

⚠️ 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

⚠️ 52 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

❌ 52 regressed benchmarks
⏩ 98 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_perf_client_calls[sync] 19.3 ms 44.5 ms -56.71%
❌ test_perf_client_calls[async] 21.5 ms 48.6 ms -55.84%
❌ test_perf_extreme_large_schema 8.4 s 17.7 s -52.86%
❌ test_perf_load_pyproject_config[mapping-None] 183.6 µs 383 µs -52.07%
❌ test_perf_load_pyproject_config[mapping-multiple] 189.8 µs 394.8 µs -51.92%
❌ test_perf_scalar_root_collapsed_builtin 108.7 ms 225.4 ms -51.78%
❌ test_perf_load_pyproject_config[config-multiple] 191.6 µs 393.9 µs -51.37%
❌ test_perf_deep_nested 3 s 6.1 s -51.21%
❌ test_perf_load_pyproject_config[config-None] 183.6 µs 375.9 µs -51.16%
❌ test_perf_complex_refs 1.1 s 2.3 s -50.75%
❌ test_perf_simple_msgspec_unset_field_rendering 287.1 ms 581.6 ms -50.64%
❌ test_perf_graphql_style_pydantic_v2 452.9 ms 916.6 ms -50.59%
❌ test_perf_aws_style_openapi_pydantic_v2 1.2 s 2.4 s -50.5%
❌ test_perf_kubernetes_style_pydantic_v2 1.5 s 3 s -50.45%
❌ test_perf_all_options_enabled 3.2 s 6.5 s -50.17%
❌ test_perf_duplicate_names 572.4 ms 1,144.8 ms -50%
❌ test_perf_local_reference_file_resolution 72.9 ms 145.5 ms -49.91%
❌ test_perf_unique_items_runtime_scalar_validation 1.6 ms 3.1 ms -49.87%
❌ test_perf_stripe_style_pydantic_v2 1.1 s 2.3 s -49.61%
❌ test_perf_pydantic_field_name_resolution 1.4 ms 2.7 ms -49.53%
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing next11-9 (c8b8d68) with next11-8 (7b58db2)

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. ↩

@koxudaxi
Koudai Aono (koxudaxi) merged commit d790ca3 into main Nov 2, 2026
163 of 164 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the next11-9 branch November 2, 2026 01:34
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: The diff is an internal refactor. The private helper _has_root_field_constraints moved from parser/_passes/_shared.py to model/base.py and gained a row parameter whose default keeps the old behaviour. The inline declared-constraints checks in _target_binding.py and collapse_site_facts now call it with row declared, which gives the same result. The direct assignments of field.required and use_default_with_required in jsonschema.py and _rw_split.py now go through GraphBuilder.require_field with what appear to be the same values, though at the jsonschema.py sites the old code never reset the default flag and the body of require_field is not in the diff, so that equivalence could not be fully confirmed. The other changes are documentation table rows and a generation store allowlist update. No public CLI options, Python API, templates, default values, Python version support or error handling are changed. The behaviour diff gate does show accepted cells, but they describe allOf schemas whose parts admit no object now becoming RootModel or a msgspec alias. The gate compares against the last release, so it includes changes merged since then, and this diff does not touch allOf handling, so those cells are not attributable to this PR. The remaining cells are crash-fix or both-fail, which do not change behaviour.


This analysis was produced by the release draft workflow

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🎉 Released in 0.88.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