You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bind the model a $ref names, not a root model another use made there - #6771
Generated streaming clients now use the schema-specific event models for event and NDJSON streams, improving the accuracy of stream item types across synchronous and asynchronous helpers.
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.
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 binding lookup now uses recorded declaration types for value projections and follows references when resolving properties. Generated stream plans and helper annotations now use the referenced Event or LogEntry models instead of item-schema wrapper types.
Changes: Stream item binding
Layer / File(s)
Summary
Resolve recorded declaration types src/datamodel_code_generator/_target_binding.py
The binding lookup no longer depends on direction. Value projections use a recorded declaration DataType when available, and property resolution follows its reference.
Expected stream plans and synchronous and asynchronous helper annotations use Event or LogEntry instead of item-schema wrapper types across the listed client configurations.
Issue 6594: The changes cover the same item-stream and $ref binding path, but the PR does not claim to fix that issue’s streaming failure.
Merge Risk: Minimal · previous review 065a6
This change makes generated stream plans and helpers use the model a $ref names, such as Event or LogEntry, instead of a root wrapper. Reviewed evidence shows the generated codecs and annotations agree, and no concrete merge-blocking risk remains.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the core fix: a $ref-only itemSchema should bind the model the $ref names, not a root model that another use created at that location. The changeset alters _target_binding.py so the de…
Linked Issues check
[#6770] The issue requires that a $ref-only itemSchema produce the referenced model as the stream item type (for example EventStream[models.Event]) for every output model type, including pydantic_v2.B…
Out of Scope Changes check
All reported changes relate to the #6770 behavior. The source change in _target_binding.py alters how a declaration's recorded DataType is selected for $ref-based item types. The remaining changes are…
Full details: Title check
Explanation
The title names the core fix: a $ref-only itemSchema should bind the model the $ref names, not a root model that another use created at that location. The changeset alters _target_binding.py so the declared DataType is selected before resolving the emitted model reference, and the expected outputs switch stream item types from ItemSchema/ItemSchemaModel wrappers to Event and LogEntry. The title is specific and matches the linked issue, though its wording is somewhat abstract for a reader scanning history.
Full details: Linked Issues check
Explanation
[#6770] The issue requires that a $ref-only itemSchema produce the referenced model as the stream item type (for example EventStream[models.Event]) for every output model type, including pydantic_v2.BaseModel. The summary reports a source change in src/datamodel_code_generator/_target_binding.py. _SchemaUses.projection now selects the declaration's recorded DataType before it resolves an emitted model reference. bound_node returns that recorded type for "value" projections. TargetApiOpenAPIParser.property_type follows a DataType reference before it looks up the property field. The reviewable expected outputs match the requirement. In item-streams/pydantic_v2_BaseModel, _helpers.py and _async_helpers.py now return EventStream[models.Event] for /events. The same files return EventStream[models.LogEntry] for the NDJSON endpoints. _plans.py now uses models.Event for STREAM_0. The dataclasses_dataclass outputs show the same types, so the two output model types now agree. Uncertainty: the generated model_bindings.py files for both output model types match the exclusion rule !/_generated/ and were not inspected. The conclusion relies on the source change and the reviewable expected outputs. Both were read from the summary, not from the full diff.
Full details: Out of Scope Changes check
Explanation
All reported changes relate to the #6770 behavior. The source change in _target_binding.py alters how a declaration's recorded DataType is selected for $ref-based item types. The remaining changes are regenerated expected outputs under tests/data/expected/main/generation_platform/client/packages/item-streams and item-streams-declared. These outputs show the new item types for /events, /logs, /records, and /excerpt. The item-streams-declared changes update STREAM_1 to STREAM_3 to models.LogEntry, which matches the same binding behavior. The bound_node change removes the direction filter, so it applies to all callers. That broader effect is still a mechanism of this fix and is not a demonstrated unrelated change. Ignored files were not inspected. The model_bindings.py and runtime/item-streams.txt files are excluded and do not change this conclusion.
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.
Reviewing files that changed from the base of the PR and between 5152497 and 065a694.
Files ignored due to path filters: 3
tests/data/expected/main/generation_platform/client/packages/item-streams/dataclasses_dataclass/client/_generated/model_bindings.py is excluded by !**/_generated/** and included by tests/**/*.py, tests/data/expected/**/*.py
tests/data/expected/main/generation_platform/client/packages/item-streams/pydantic_v2_BaseModel/client/_generated/model_bindings.py is excluded by !**/_generated/** and included by tests/**/*.py, tests/data/expected/**/*.py
tests/data/expected/main/generation_platform/client/runtime/item-streams.txt is excluded by !tests/data/**/*.txt and included by none
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
⚠️53 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.
Reasoning: The source change in the private _target_binding module makes bound_node prefer the declaration's own type for the value projection over a model another reference emitted at the same location. The bound_node and bound signature changes are internal. The expected outputs for the item-streams client packages show the visible effect: stream helper return types, EventPlan generics and codec type parameters change from ItemSchema or ItemSchemaModel to the referenced models Event and LogEntry. For Pydantic v2 the codecs now construct the referenced model, so the runtime class of decoded items and the model named in validation errors change too. The release baseline lists no experimental features, options, presets or public names missing from 0.95.0, so this client generation behaviour is treated as released. The behaviour diff gate shows only both-fail cells, but it covers default model generation, not client generation. The documentation edits only describe the new behaviour. Overall this is a fix, but users who referenced the old item model names in their code may need to update it, so it is reported as a code generation breaking change.
Content for Release Notes
Code Generation Changes
Generated client stream helpers now type items as the model the itemSchema references - In generated Python clients, SSE, JSON Lines and NDJSON stream helpers whose itemSchema is a bare $ref now use the referenced model, for example EventStream[models.LogEntry], AsyncEventStream[models.Event] and EventPlan[models.LogEntry]. Before, they used the duplicate ItemSchema or ItemSchemaModel model generated at the item schema location. The codecs in _generated/model_bindings.py change to match. With Pydantic v2 output, decoded stream items are now instances of the referenced model, for example models.LogEntry instead of models.ItemSchemaModel, and validation error messages name that model. With dataclasses output, only the type annotations change. Code that annotates, isinstance-checks or pattern-matches stream items against models.ItemSchema or models.ItemSchemaModel has to switch to the referenced model (Bind the model a $ref names, not a root model another use made there #6771)
This analysis was produced by the release draft workflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #6770
Summary by CodeRabbit