-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix core schema simplification when serialization schemas are involved in specific scenarios #10155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…d in specific scenarios
Deploying pydantic-docs with
|
| Latest commit: |
36c76df
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://30c993b1.pydantic-docs.pages.dev |
| Branch Preview URL: | https://9319.pydantic-docs.pages.dev |
CodSpeed Performance ReportMerging #10155 will not alter performanceComparing Summary
|
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| @@ -212,6 +212,7 @@ def _handle_other_schemas(self, schema: core_schema.CoreSchema, f: Walk) -> core | |||
| def _handle_ser_schemas(self, ser_schema: core_schema.SerSchema, f: Walk) -> core_schema.SerSchema: | |||
| schema: core_schema.CoreSchema | None = ser_schema.get('schema', None) | |||
| if schema is not None: | |||
| ser_schema = ser_schema.copy() | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ser_schema = ser_schema.copy() | |
| ser_schema = smart_deepcopy(ser_schema) |
Can we match the approach used in this PR? #9980
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather stick with .copy here, as it is for the rest of the _WalkSchema implementation. deepcopy on a dict is slower and does not have any impact here, as .copy will create a shallow copy and this is enough (as we are only changing a top level key here, in this case the 'schema' key).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good!
Fixes #9319
After a lot of debugging in the core schema generation internals, I managed to find where the issue was coming from. I'm still unsure why using a
Sequenceinstead of alistleads to the original issue. My best guess is that is it purely a coincidence:Sequencecreates a different core schema, and probably it led to a really specific scenario where not having the serialization schema copied would result in a crash later on as theModel1definition wasn't saved retained (I suspect this issue where the serialization schema isn't copied already happened in other cases, but had no incident).Change Summary
Related issue number
Checklist