Skip to content

Name --dedupe-request-response-variants in the errors that the 0.86.0 request-response decisions raise - #6208

Merged
Koudai Aono (koxudaxi) merged 5 commits into
bug-g10from
bug-g14
Nov 4, 2026
Merged

Koudai Aono (koxudaxi) merged 5 commits into
bug-g10from
bug-g14

Conversation

@koxudaxi

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

Copy link
Copy Markdown
Member

Fixes: #5266
Fixes: #5556
Fixes: #5570
Fixes: #5613
Fixes: #5706

Summary by CodeRabbit

  • Bug Fixes
    • Improved diagnostics for schemas that cannot be resolved when generating separate request and response models. Messages now point to the option that can enable deduplication of those variants.
    • Corrected generation for discriminated unions whose enum tags are referenced indirectly.

… request-response facts raise

Without --dedupe-request-response-variants the read/write facts of a key come from a temporary parse and the walk reads
every reference of a key, as in 0.86.0 (`legacy-rw-parsed-facts`, `legacy-rw-unowned-parent-fields`, both kept). An input
those reads stop on stopped with the bare error of the read, or with a traceback.

An error raised by the walk of the references of a key (`Unresolved $id reference '#node'` for a `$dynamicRef` inside an
`$id`d `$defs` entry) or by the lookup of the source of a variant (`$ref file not found: <dir>/p` for an allOf child
defined before its base, whose parent's inline model is parsed at no owner path) now ends with the hint that
`--dedupe-request-response-variants` decides the variants from the schema graph and can generate such schemas. The error
for classes that cannot be ordered under request-response is an `Error`, so the command line prints its message instead
of a traceback, and it lists the references of each class in sorted order, so its text no longer changes between runs
with the hash seed. The graph node of a special path is read in one place for both modes: a path the parser makes names no
schema of any document, so the walk reads nothing there (#5706 stopped with `NotImplementedError` until #6006; a test
pins the server and request-response run).

Only the text of an error and the type of the error for unordered classes change; no input that generated stops, and the
output of every input that generates is unchanged.

Fixes: #5266
Fixes: #5556
Fixes: #5570
Fixes: #5613
Fixes: #5706
@coderabbitai

coderabbitai Bot commented Nov 4, 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 changes update unresolved-reference diagnostics and legacy request/response variant analysis. They sort and deduplicate unresolved paths, add deduplication-option guidance to selected errors, and add regression tests for schema generation and FastAPI output.

Changes: Request/response variant resolution

Layer / File(s) Summary
Unresolved-reference diagnostics
src/datamodel_code_generator/parser/_passes/_shared.py, src/datamodel_code_generator/parser/_passes/settle.py, tests/main/test_error_messages.py, tests/main/test_error_messages.refs, tests/data/expected/main/malformed/*
Unresolved-reference paths are sorted and deduplicated. When legacy request/response mode is active, the unresolved-model error includes guidance about --dedupe-request-response-variants. Regression tests cover three schema cases both without and with deduplication enabled.
Legacy variant graph handling
src/datamodel_code_generator/parser/_rw_split.py, tests/api_generation/test_fastapi_cli.py, tests/api_generation/test_fastapi_cli.refs, tests/data/expected/main/generation_platform/fastapi/fastapi_cli_request_response_discriminated_enum.py
Legacy graph lookups add the deduplication hint to propagated errors. Special paths return no reference facts. The FastAPI regression test checks generated output for a discriminated enum.

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

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

Possibly related PRs

Merge Risk: Minimal · previous review a761c

The changes improve request-response diagnostics and special-path handling, with regression coverage for the affected scenarios. No merge-blocking issue is established.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Linked Issues check Warning Assessed against #5266, #5556, #5570, #5613, and #5706. No repository inspection was possible. This result relies on the supplied summary, the PR objectives, and the test expectations described in the… Choose one of two remediations.
(a) Make the legacy request-response read path generate output for the #5266, #5556, and #5570/#5613 inputs without --dedupe-request-response-variants. Generate the request and response variants, as the issue…
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the main change: adding --dedupe-request-response-variants to relevant request-response error messages. It is specific and related to the pull request.
Out of Scope Changes check Passed The reviewed changes connect to the linked issues or to their tests.
- parser/_passes/_shared.py: with_dedupe_request_response_hint adds the hint text used by the new error messages for #5570 and #561…
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 with cyclomatic complexity of at least 2. Documentat…
Full details: Out of Scope Changes check

Explanation

The reviewed changes connect to the linked issues or to their tests.

  • parser/_passes/_shared.py: with_dedupe_request_response_hint adds the hint text used by the new error messages for #5570 and #5613.
  • parser/_passes/settle.py: sort_data_models replaces unresolved_hint with legacy_request_response. Reference paths are sorted and deduplicated for #5570 and #5613. The flag is set only when read/write variants are enabled and deduplication is off.
  • parser/_rw_split.py: legacy_rw_errors wraps legacy reference-fact reads and the variant-source schema check. It re-raises errors as Error with the hint. Special-path handling supports #5706.
  • tests/api_generation/test_fastapi_cli.py and its .refs file, with the matching expected output: regression coverage for #5706.
  • tests/main/test_error_messages.py and its .refs file, with the matching expected outputs: regression coverage for #5266, #5556, #5570, and #5613.
    The ignored input fixtures under tests/data/malformed/ and tests/data/generation_platform/ are test inputs. They are excluded from review, and this result does not depend on their contents. No unrelated behavior change appears in the summary.
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 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 8 functions across 9 files. (2 skipped: 2 unsupported.)

Full details: Linked Issues check

Explanation

Assessed against #5266, #5556, #5570, #5613, and #5706. No repository inspection was possible. This result relies on the supplied summary, the PR objectives, and the test expectations described in the summary.

Partly met:

  • [#5570, #5613] Reference lists in the unresolved-class error are sorted and deduplicated (settle.py). The error now names --dedupe-request-response-variants. The error text is stable, but the generation requirement is not met (see below).
  • [#5706] Special parser paths are excluded from the variant graph walk, and reference-fact lookup returns (False, ()) for them. A new FastAPI CLI test covers a discriminated enum with a server target, and its expected output shows generation succeeds. This appears to meet #5706.

Unmet:

  • [#5266, #5556, #5570, #5613] All four issues require generation to succeed with --read-only-write-only-model-type request-response, without any extra option. Their reproduction commands do not include --dedupe-request-response-variants. The updated tests/main/test_error_messages.py cases expect the legacy request-response path to still raise errors for the #5266 (allOf child before base), #5556 ($dynamicRef in $id'd $defs), and #5570/request-response split of a recursive discriminated union fails with unresolved classes, in a message whose order varies between runs #5613 (recursive discriminator) fixtures. The generation success is expected only when the option is enabled. The PR objectives also state that the change alters only error text. The linked issues therefore remain unfixed in the default mode.

Resolution

Choose one of two remediations.
(a) Make the legacy request-response read path generate output for the #5266, #5556, and #5570/#5613 inputs without --dedupe-request-response-variants. Generate the request and response variants, as the issues specify. Update the three expected outputs and the test_error_messages.py cases to expect success. Keep the sorted, hinted error text only for inputs that still cannot be resolved.
(b) If the maintainers keep the option-only behavior, remove Fixes: #5266, #5556, #5570, and #5613 from the PR description. Keep those issues open, and retain only #5706 as fixed. Record the option-only behavior in the issues.

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

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 1d2f85f and a761c96.

Files ignored due to path filters: 4
  • tests/data/generation_platform/fastapi/cli/request-response-discriminator.yaml is excluded by !tests/data/**/*.yaml and included by none
  • tests/data/malformed/request_response_allof_child_before_base.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/malformed/request_response_dynamic_ref_in_id_defs.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/malformed/request_response_recursive_discriminator.yaml is excluded by !tests/data/**/*.yaml and included by none
Files selected for processing: 11
  • src/datamodel_code_generator/parser/_passes/_shared.py
  • src/datamodel_code_generator/parser/_passes/settle.py
  • src/datamodel_code_generator/parser/_rw_split.py
  • tests/api_generation/test_fastapi_cli.py
  • tests/api_generation/test_fastapi_cli.refs
  • tests/data/expected/main/generation_platform/fastapi/fastapi_cli_request_response_discriminated_enum.py
  • tests/data/expected/main/malformed/request_response_dedupe_generates_legacy_stops.py
  • tests/data/expected/main/malformed/request_response_dedupe_generates_legacy_stops~request_response_dedupe_generates_legacy_stops[dynamic-ref-in-id-defs].py
  • tests/data/expected/main/malformed/request_response_dedupe_generates_legacy_stops~request_response_dedupe_generates_legacy_stops[recursive-discriminator].py
  • tests/main/test_error_messages.py
  • tests/main/test_error_messages.refs

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

@koxudaxi
Koudai Aono (koxudaxi) marked this pull request as ready for review November 4, 2026 10:06
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 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-04T10:08:02.965301Z a761c96 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 4, 2026

Copy link
Copy Markdown
Contributor

@codspeed

codspeed Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 49.91%

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 improved benchmarks
⏩ 98 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_perf_simple_msgspec_unset_field_rendering 584.1 ms 324.8 ms +79.84%
⚡ test_perf_client_calls[sync] 44.5 ms 25 ms +78.19%
⚡ test_perf_load_pyproject_config[mapping-None] 233.7 µs 133.4 µs +75.13%
⚡ test_perf_client_calls[async] 48.6 ms 28 ms +73.28%
⚡ test_perf_load_pyproject_config[config-multiple] 254.5 µs 147.9 µs +72.05%
⚡ test_perf_load_pyproject_config[mapping-multiple] 252.1 µs 148 µs +70.36%
⚡ test_perf_load_pyproject_config[config-None] 229.3 µs 134.8 µs +70.13%
⚡ test_perf_scalar_root_collapsed_builtin 231.1 ms 140.1 ms +64.98%
⚡ test_perf_ordinary_array_constraint_generation 2.4 s 1.5 s +61.94%
⚡ test_perf_large_models_pydantic_v2_noformat 1,598.7 ms 999.1 ms +60.01%
⚡ test_perf_large_models_single_module_stdout 1.9 s 1.2 s +59.63%
⚡ test_perf_local_reference_file_resolution 154.7 ms 97.3 ms +59.08%
⚡ test_perf_large_models_typed_dict[legacy-requiredness] 1,398.3 ms 881.3 ms +58.66%
⚡ test_perf_large_models_msgspec 2.3 s 1.5 s +56.99%
⚡ test_perf_large_models_dataclass_builtin 1.6 s 1 s +56.49%
⚡ test_perf_large_models_pydantic_v2 4.3 s 2.8 s +55.79%
⚡ test_perf_multiple_files_input 4.7 s 3 s +54.6%
⚡ test_perf_deep_nested 6.7 s 4.4 s +54.25%
⚡ test_perf_large_models_pydantic_v2_builtin 1.6 s 1 s +53.43%
⚡ test_perf_large_models_pydantic_v2_builtin_double_quotes 1.7 s 1.1 s +52.59%
... ... ... ... ...

ℹ️ 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 bug-g14 (881ba47) with bug-g10 (bf684b3)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 bug-g10 (c820a3f) during the generation of this report, so 94c7314 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@koxudaxi
Koudai Aono (koxudaxi) merged commit e48f47a into main Nov 4, 2026
31 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the bug-g14 branch November 4, 2026 19:10
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: The PR only touches the legacy read/write split path, which runs when --read-only-write-only-model-type request-response is used without --dedupe-request-response-variants. First, the _is_special_path check moves into get_ref_schema_rw_model_reference_facts. The legacy path now skips parser-made marker paths instead of crashing with NotImplementedError on discriminated unions with enum tags, so this is a crash fix. Second, the internal sort_data_models in the private parser._passes.settle module swaps its unresolved_hint string parameter for a legacy_request_response bool. That module is not public API. Third, the unresolved-classes error now lists references in sorted order for deterministic text. In legacy request-response mode it is raised as datamodel_code_generator.Error rather than a bare Exception. Error is a subclass of Exception, so existing handlers still catch it, and the dedupe hint text was already appended before. Fourth, a new legacy_rw_errors context manager adds the same dedupe-option hint to Error messages raised by reference-fact reads in legacy mode, which only adds text. The behaviour diff gate shows only both-fail, crash-fix and no-behaviour cells and no accepted or violation cells, so default generated output does not change. No CLI options, public API, templates, default values or Python version support were removed or changed. All other changes are new tests and fixtures.


This analysis was produced by the release draft workflow

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

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