Skip to content

Restore the 0.86.0 dialect flag reads and constructor field ordering under --strip-default-none - #5394

Merged
Koudai Aono (koxudaxi) merged 3 commits into
rel-0870-perffrom
rel-0870-restore
Oct 27, 2026
Merged

Koudai Aono (koxudaxi) merged 3 commits into
rel-0870-perffrom
rel-0870-restore

Conversation

@koxudaxi

@koxudaxi Koudai Aono (koxudaxi) commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Improved JSON Schema $ref sibling handling when processing directories containing documents from different schema drafts. Draft 4, 6, and 7 continue to follow their specific sibling-keyword rules.
    • Corrected generated constructor field ordering for optional fields with None defaults, including inherited and overridden fields.
  • Documentation
    • Clarified how constructor ordering handles defaults at different processing stages.

… had, so a draft-07 document no longer decides it for the 2020-12 documents of a directory
… when ordering constructor fields inside the module loop
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

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.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 022559a and c34989b.

Files ignored due to path filters: 3
  • docs/llms-full.txt is excluded by none and included by none
  • tests/data/jsonschema/ref_sibling_dialect_directory/draft07.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/jsonschema/ref_sibling_dialect_directory/model.json is excluded by !tests/data/**/*.json and included by none
Files selected for processing: 33
  • docs/architecture.md
  • src/datamodel_code_generator/model/base.py
  • src/datamodel_code_generator/parser/_passes/render_prep.py
  • src/datamodel_code_generator/parser/jsonschema.py
  • tests/data/expected/main/jsonschema/main_jsonschema/ref_sibling_dialect_directory[dataclasses.dataclass]/__init__.py
  • tests/data/expected/main/jsonschema/main_jsonschema/ref_sibling_dialect_directory[dataclasses.dataclass]/draft07.py
  • tests/data/expected/main/jsonschema/main_jsonschema/ref_sibling_dialect_directory[dataclasses.dataclass]/model.py
  • tests/data/expected/main/jsonschema/main_jsonschema/ref_sibling_dialect_directory[msgspec.Struct]/__init__.py
  • tests/data/expected/main/jsonschema/main_jsonschema/ref_sibling_dialect_directory[msgspec.Struct]/draft07.py
  • tests/data/expected/main/jsonschema/main_jsonschema/ref_sibling_dialect_directory[msgspec.Struct]/model.py
  • tests/data/expected/main/jsonschema/main_jsonschema/ref_sibling_dialect_directory[pydantic_v2.BaseModel]/__init__.py
  • tests/data/expected/main/jsonschema/main_jsonschema/ref_sibling_dialect_directory[pydantic_v2.BaseModel]/draft07.py
  • tests/data/expected/main/jsonschema/main_jsonschema/ref_sibling_dialect_directory[pydantic_v2.BaseModel]/model.py
  • tests/data/expected/main/jsonschema/main_jsonschema/ref_sibling_dialect_directory[pydantic_v2.dataclass]/__init__.py
  • tests/data/expected/main/jsonschema/main_jsonschema/ref_sibling_dialect_directory[pydantic_v2.dataclass]/draft07.py
  • tests/data/expected/main/jsonschema/main_jsonschema/ref_sibling_dialect_directory[pydantic_v2.dataclass]/model.py
  • tests/data/expected/main/jsonschema/main_jsonschema/ref_sibling_dialect_directory[typing.TypedDict]/__init__.py
  • tests/data/expected/main/jsonschema/main_jsonschema/ref_sibling_dialect_directory[typing.TypedDict]/draft07.py
  • tests/data/expected/main/jsonschema/main_jsonschema/ref_sibling_dialect_directory[typing.TypedDict]/model.py
  • tests/data/expected/main/openapi/main_openapi/strip_default_none_constructor_order[pydantic-dataclass-annotated].py
  • tests/data/expected/main/openapi/main_openapi/strip_default_none_constructor_order[pydantic-dataclass-field-type-override].py
  • tests/data/expected/main/openapi/main_openapi/strip_default_none_constructor_order[pydantic-dataclass-model-type-override].py
  • tests/data/expected/main/openapi/main_openapi/strip_default_none_constructor_order[pydantic-dataclass-target-2.14].py
  • tests/data/expected/main/openapi/main_openapi/strip_default_none_constructor_order[pydantic-dataclass].py
  • tests/data/expected/main/openapi/main_openapi/type_overrides_constructor_order_modules_default[base-override-drops-inherited-default]/__init__.py
  • tests/data/expected/main/openapi/main_openapi/type_overrides_constructor_order_modules_default[base-override-drops-inherited-default]/aa.py
  • tests/data/expected/main/openapi/main_openapi/type_overrides_constructor_order_modules_default[base-override-drops-inherited-default]/common.py
  • tests/data/expected/main/openapi/main_openapi/type_overrides_constructor_order_modules_default[base-override-drops-inherited-default]/zz.py
  • tests/main/jsonschema/test_main_jsonschema.py
  • tests/main/jsonschema/test_main_jsonschema.refs
  • tests/main/openapi/test_main_openapi.py
  • tests/main/openapi/test_main_openapi.refs
  • tests/main/test_payload_validation.refs
Files with no reviewable changes: 4
  • tests/data/expected/main/openapi/main_openapi/type_overrides_constructor_order_modules_default[base-override-drops-inherited-default]/init.py
  • tests/data/expected/main/openapi/main_openapi/type_overrides_constructor_order_modules_default[base-override-drops-inherited-default]/common.py
  • tests/data/expected/main/openapi/main_openapi/type_overrides_constructor_order_modules_default[base-override-drops-inherited-default]/aa.py
  • tests/data/expected/main/openapi/main_openapi/type_overrides_constructor_order_modules_default[base-override-drops-inherited-default]/zz.py

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

Walkthrough

The changes update constructor ordering to account for construction defaults and make JSON Schema $ref sibling support depend on the current document’s dialect. Tests and generated-output expectations cover both changes.

Changes: Constructor Field Ordering

Layer / File(s) Summary
Construction-default ordering
src/datamodel_code_generator/model/base.py, src/datamodel_code_generator/parser/_passes/render_prep.py, docs/architecture.md
The ordering context tracks construction defaults separately from rendered nullability. The render-preparation pass applies this context during early ordering.
Constructor output expectations
tests/data/expected/main/openapi/.../strip_default_none_constructor_order[*].py, tests/data/expected/main/openapi/.../base-override-drops-inherited-default/*, tests/main/openapi/test_main_openapi.py, tests/main/openapi/test_main_openapi.refs
Updated expected outputs show affected None-default fields as keyword-only. OpenAPI test descriptions and fixture references reflect the constructor-ordering cases.

JSON Schema Reference Sibling Dialects

Layer / File(s) Summary
Root-specific dialect detection
src/datamodel_code_generator/parser/jsonschema.py
A shared helper selects an explicit configured version or detects the supplied root’s version. The sibling check evaluates the current root.
Mixed-dialect generation expectations
tests/main/jsonschema/test_main_jsonschema.py, tests/main/jsonschema/test_main_jsonschema.refs, tests/data/expected/main/jsonschema/.../ref_sibling_dialect_directory[*]/*, tests/main/test_payload_validation.refs
Tests and generated expectations cover mixed-dialect documents across dataclasses, msgspec, Pydantic BaseModel, Pydantic dataclass, and TypedDict.

Priority: Normal

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

Change: Bug fix

Merge Risk: Minimal · previous review c3498

The constructor change matches the intended ordering behavior. No identified issue blocks merging after normal 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 identifies both main changes: restoring per-document dialect flag handling and correcting constructor field ordering under --strip-default-none.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within survi…
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 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 22 files. (7 skipped: 4 unsupported, 3 too large.)

Finishing Touches: 💡 1
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • 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

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 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-10-27T15:20:21.406977Z c34989b PR opened
ℹ️ 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.

@codspeed

codspeed Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 30.37%

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

⚠️ Base and head ran on different runner types

Some benchmarks with significant performance changes were compared across different runner types, so the changes might not come from the code. Run base and head on the same runner type, or use CodSpeed Macro Runners for more stable results.

Learn more about Macro Runners

Open the report in CodSpeed to investigate

⚡ 52 improved benchmarks
⏩ 98 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_perf_unique_items_runtime_scalar_validation 2.5 ms 1.6 ms +57.88%
⚡ test_perf_pydantic_field_name_resolution 1,533 µs 982.1 µs +56.09%
⚡ test_perf_unique_items_nested_model_validation 2.4 ms 1.6 ms +46.68%
⚡ test_perf_extreme_large_schema 11.5 s 7.9 s +45.67%
⚡ test_perf_graphql_style_pydantic_v2 590.3 ms 406.1 ms +45.35%
⚡ test_perf_simple_pydantic_v2_field_construction 8.6 ms 6 ms +42.67%
⚡ test_perf_aws_style_openapi_pydantic_v2 1.6 s 1.1 s +41.43%
⚡ test_perf_stripe_style_pydantic_v2 1.6 s 1.1 s +40.78%
⚡ test_perf_complex_refs 1.5 s 1.1 s +40.75%
⚡ test_perf_large_models_pydantic_v2 2.5 s 1.8 s +40.28%
⚡ test_perf_kubernetes_style_pydantic_v2 1.9 s 1.4 s +40.08%
⚡ test_perf_all_options_enabled 4.1 s 3 s +38.93%
⚡ test_perf_duplicate_names 757.6 ms 556 ms +36.26%
⚡ test_perf_client_calls[async] 27.1 ms 20 ms +35.98%
⚡ test_perf_unique_items_collapsed_builtin 1.4 s 1.1 s +35%
⚡ test_perf_unique_items_schema_validators 1.5 s 1.1 s +34.28%
⚡ test_perf_empty_pydantic_v2_field_render_plans 25.8 ms 19.2 ms +34.14%
⚡ test_perf_unique_items_permuted_object_validation 54.8 ms 41 ms +33.61%
⚡ test_perf_client_calls[sync] 23.9 ms 17.9 ms +33.53%
⚡ test_perf_openapi_large 2.3 s 1.7 s +33.18%
... ... ... ... ...

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

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing rel-0870-restore (64d292e) with rel-0870-perf (022559a)2

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

  2. No successful run was found on rel-0870-perf (28759f8) during the generation of this report, so 776791e was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@github-actions

Copy link
Copy Markdown
Contributor

@codecov

codecov Bot commented Oct 27, 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 546c492 into main Oct 27, 2026
26 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the rel-0870-restore branch October 27, 2026 17:31
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: Breaking changes detected

Reasoning: I read the whole diff. It makes two changes. First, in the JSON Schema parser, the check for whether keywords beside a $ref count as part of the schema now uses the dialect of the document being parsed, not a value cached from the first document. The new test says this restores the 0.86.0 behavior for a 2020-12 document read after a draft-07 one, so I treat it as a regression fix, not a breaking change. Second, a new context variable makes the early constructor ordering for Pydantic dataclasses count a None default that strip-default-none may keep as no default. The early ordering is the one used when order-constructor-fields-by final-names is off, which is the default. The expected outputs change visibly. In strip_default_none_constructor_order, a subclass field after an inherited default goes from a positional None default to Field(None, kw_only=True). In the type-overrides modules default case, subclass fields that were keyword-only now stay positional. A field turning keyword-only changes the generated constructor signature and breaks callers that pass that field positionally, so I report it as a code generation change. No CLI options, public API, templates or Python version support are removed or changed. Deleting the Windows msgspec observation snapshot and adding the refs entries only affects test infrastructure.

Content for Release Notes

Code Generation Changes

  • Pydantic dataclass constructor ordering with --strip-default-none now counts a kept None default as no default - This applies when generating pydantic_v2.dataclass models with --strip-default-none and without --order-constructor-fields-by final-names. The constructor ordering that runs while modules are processed now treats a None default that the option may keep as no default, the same way the construction key does. A subclass field that follows an inherited default and was previously rendered as n: Plain | None = None is now rendered as n: Plain | None = Field(None, kw_only=True). That makes it keyword-only, so code that passes such fields positionally must switch to keyword arguments. In the other direction, when a base's --type-overrides drops an inherited default, subclass fields that were previously forced keyword-only with Field(kw_only=True) or Field(..., kw_only=True) now stay positional, matching the --order-constructor-fields-by final-names output (Restore the 0.86.0 dialect flag reads and constructor field ordering under --strip-default-none #5394)

This analysis was produced by the release draft workflow

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