Skip to content

Report a response status given by both an integer and a string key as a server and client schema error - #5284

Merged
Koudai Aono (koxudaxi) merged 1 commit into
fix-5204-msgspec-any-unionfrom
fix-5271-dup-status-keys
Oct 24, 2026
Merged

Koudai Aono (koxudaxi) merged 1 commit into
fix-5204-msgspec-any-unionfrom
fix-5271-dup-status-keys

Conversation

@koxudaxi

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

Copy link
Copy Markdown
Member

Fixes: #5271

Summary by CodeRabbit

  • Bug Fixes
    • API specifications that define the same response status using both numeric and text keys are now rejected with a clear validation error, rather than being handled ambiguously. This makes duplicate response statuses easier to identify when generating clients or servers.

… a server and client schema error

YAML loads a status key such as `200` as a number, so one responses object can give the same status twice, as `200`
and as `'200'`. Server and client generation locate every response by the text of its status, so such a document
crashed with the internal BindingCaptureError "Source pointer is ambiguous between string and integer keys". These
runs now stop with "Error at schema path '<doc>#/paths/~1pets/get/responses/200': response status 200 is given by two
keys, 200 and '200'", like the key errors of #5248 and #5260, and write nothing. Model generation, and server and
client output of documents that give each status once, stay the same.

Fixes: #5271
@coderabbitai

coderabbitai Bot commented Oct 24, 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 e853b3e and dcc1392.

Files ignored due to path filters: 3
  • tests/data/expected/main/generation_platform/client/bindings/session-ambiguous-status.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/generation_platform/client/bindings.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/malformed/integer_and_string_status.yaml is excluded by !tests/data/**/*.yaml and included by none
Files selected for processing: 3
  • src/datamodel_code_generator/_target_binding.py
  • tests/api_generation/test_generate_targets.py
  • tests/api_generation/test_generate_targets.refs

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

Response status keys are normalized before binding. If distinct keys normalize to the same status, generation raises a schema parse error. Tests cover the integer-and-string duplicate case for client and server generation.

Changes: Response status key validation

Layer / File(s) Summary
Normalize and validate response statuses
src/datamodel_code_generator/_target_binding.py, tests/api_generation/test_generate_targets.py, tests/api_generation/test_generate_targets.refs
Response status keys are normalized before bindings are created. Colliding keys now raise SchemaParseError at the status pointer. Tests add client and server cases for integer and string keys representing the same status.

Priority: Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related PRs

Merge Risk: Minimal · up to dcc13

No actionable issue is identified in the duplicate response-status handling; the PR is mergeable 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 and accurately summarizes the main change: duplicate response statuses supplied as integer and string keys now produce server and client schema errors.
Linked Issues check Passed The changes satisfy the coding requirement in #5271. _Contracts.statuses normalizes response keys and rejects an integer/string collision, such as 200 and '200', with SchemaParseError at the r…
Out of Scope Changes check Passed The reviewed changes are limited to response-status validation in _target_binding.py and regression tests for the duplicate-status failure. These changes directly support #5271. No unrelated product…
Docstring Coverage Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. (1 skipped: 1 u…
Full details: Linked Issues check

Explanation

The changes satisfy the coding requirement in #5271. _Contracts.statuses normalizes response keys and rejects an integer/string collision, such as 200 and '200', with SchemaParseError at the response-status schema path. operation uses the normalized mapping and no longer raises BindingCaptureError. Regression coverage adds the malformed fixture and expected client and server error cases.

Full details: Out of Scope Changes check

Explanation

The reviewed changes are limited to response-status validation in _target_binding.py and regression tests for the duplicate-status failure. These changes directly support #5271. No unrelated product behavior or unrelated files are identified in the supplied summary.

Full details: Docstring Coverage

Explanation

Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 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

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 24, 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-24T03:50:01.999047Z dcc1392 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.

@github-actions

Copy link
Copy Markdown
Contributor

@codspeed

codspeed Bot commented Oct 24, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 96.79%

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

⚡ 50 improved benchmarks
⏩ 98 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_perf_client_calls[async] 46.9 ms 19.4 ms ×2.4
⚡ test_perf_client_calls[sync] 42.3 ms 17.6 ms ×2.4
⚡ test_perf_load_pyproject_config[mapping-multiple] 385.6 µs 180.8 µs ×2.1
⚡ test_perf_false_reference_validation 380.7 ms 179.1 ms ×2.1
⚡ test_perf_large_models_pydantic_v2 4.1 s 2 s ×2.1
⚡ test_perf_all_options_enabled 7.4 s 3.5 s ×2.1
⚡ test_perf_load_pyproject_config[mapping-None] 372.7 µs 178 µs ×2.1
⚡ test_perf_complex_refs 2.5 s 1.2 s ×2.1
⚡ test_perf_inherited_required_fields[required-derived-first] 810.3 ms 389.7 ms ×2.1
⚡ test_perf_pydantic_field_name_resolution 1,996.7 µs 964.2 µs ×2.1
⚡ test_perf_graphql_style_pydantic_v2 945.6 ms 457.1 ms ×2.1
⚡ test_perf_deep_nested 6.5 s 3.1 s ×2.1
⚡ test_perf_load_pyproject_config[config-None] 367.4 µs 178 µs ×2.1
⚡ test_perf_load_pyproject_config[config-multiple] 380.1 µs 184.8 µs ×2.1
⚡ test_perf_duplicate_names 1,184.2 ms 576.7 ms ×2.1
⚡ test_perf_multiple_files_input 4.3 s 2.1 s ×2
⚡ test_perf_extreme_large_schema 17.8 s 8.7 s ×2
⚡ test_perf_unique_items_runtime_scalar_validation 3.2 ms 1.5 ms ×2
⚡ test_perf_unique_items_nested_model_validation 3.2 ms 1.6 ms ×2
⚡ test_perf_kubernetes_style_pydantic_v2 3 s 1.5 s ×2
... ... ... ... ...

ℹ️ 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 fix-5271-dup-status-keys (dcc1392) with fix-5204-msgspec-any-union (e853b3e)

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 Oct 24, 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 b4832fd into main Oct 24, 2026
131 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the fix-5271-dup-status-keys branch October 24, 2026 07:54
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: The PR changes how target binding handles an OpenAPI YAML document where a response status appears twice, once as an integer key like 200 and once as the string key '200'. Before, this raised the internal BindingCaptureError from the private _generation_contract module with a generic message. The test fixture notes called that a bug, since the internal exception escaped instead of becoming a diagnostic. Now a new static helper, statuses, finds the duplicate and raises the public SchemaParseError, a subclass of Error, with the schema path and a clear message. Input that was rejected before is still rejected and nothing is written. Only the exception moves from an internal class to the documented public error type, so this is a bug fix in error reporting, not a breaking change. Valid schemas are unaffected: response statuses are still turned into strings and processed in the same order. There are no changes to generated code output, templates, CLI options, public API signatures, defaults, or supported Python versions. The other changed files are tests and fixtures.


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.

Server/client generation crashes on a responses map with the same status as integer and string keys

1 participant