[python] preserve public model field names - #24131
Conversation
aa81213 to
1105d36
Compare
|
GitHub does not permit me to request reviews directly in this repository. @fa0311, could you review the Pydantic validation and post-definition @wing328, could you review the Python generator scope and generated-sample |
There was a problem hiding this comment.
No issues found across 29 files
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
Re-trigger cubic
2aaafa2 to
8f41390
Compare
|
thanks for the PR moving forward please cc @cbornet (2017/09) @tomplus (2018/10) @krjakbrjak (2023/02) @fa0311 (2023/10) (python technical committee) |
8f41390 to
6ad994f
Compare
|
Will do. |
6ad994f to
6126d40
Compare
6126d40 to
5457355
Compare
|
Resolved the merge conflict with #24129. Would appreciate a review! |
5457355 to
fdedc98
Compare
nameMappings currently become Pydantic storage names. Mappings such as continue=_continue therefore generate models that cannot import, while mappings that collide with model imports or members can shadow them. Keep OpenAPI wire names, requested public names, and collision-free Pydantic storage names separate. Accept wire or public input, reject payloads containing both, serialize wire names, and expose requested names through forwarding properties. Reject cross-field collisions across generated inheritance hierarchies and collisions with known generated and Pydantic 2.11 members before generation. Install forwarding properties after model definitions and postponed model rebuilds, preserving the Pydantic 2.11 minimum. Models without explicit nameMappings retain existing generation. Normalized storage names remain real Pydantic fields and are observable through attribute access and assignment, introspection, unaliased dumps, and attribute-based validation. Mapping inputs, requests, responses, and generated API surfaces use wire or public names instead. oneOf and anyOf wrapper models retain their existing behavior.
Regenerate the modern Python petstore clients after separating wire, public, and storage names. The fixtures cover leading-underscore names, Pydantic and generated-member collisions, import names, and inherited fields while retaining the Pydantic 2.11 minimum.
fdedc98 to
48180dc
Compare
|
no question/feedback from anyone. i think we can give it a try thanks for the PR |
nameMappingscurrently become Pydantic storage names. A mapping suchas
continue=_continuetherefore generates a model that cannot beimported, while mappings that collide with model imports or members can
shadow them.
Keep OpenAPI wire names, requested public names, and collision-free
Pydantic storage names separate. Accept either wire or public input and
reject payloads containing both instead of assigning silent precedence.
Serialize wire names and expose requested names through forwarding
properties. Reject cross-field collisions across generated inheritance
hierarchies and collisions with known generated and Pydantic 2.11
members before generation.
Install forwarding properties after model definitions and postponed
model rebuilds, preserving the Pydantic 2.11 minimum. The
schemamapping remains an explicit exception because it replaces Pydantic's
deprecated
BaseModel.schema()method. Models without explicitnameMappingsretain their existing output.Normalized storage names remain real Pydantic fields and are observable
through attribute access and assignment, introspection, unaliased dumps,
and attribute-based validation. Mapping inputs, requests, responses, and
generated API surfaces use wire or public names instead.
oneOfandanyOfwrapper models do not receive forwardingproperties or input-name preprocessing.
Closes #24123.