Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.2k
Do not cache parametrized models when in the process of parametrizing another model#10704
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
cloudflare-workers-and-pagesbot commentedOct 24, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Deploying pydantic-docs with |
Latest commit: | 6194229 |
Status: | ✅ Deploy successful! |
Preview URL: | https://24ecaaa2.pydantic-docs.pages.dev |
Branch Preview URL: | https://10279-2.pydantic-docs.pages.dev |
codspeed-hqbot commentedOct 24, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
CodSpeed Performance ReportMerging#10704 willnot alter performanceComparing Summary
|
@Viicos, this should be unblocked now :) |
assert module.Foo.model_fields['bar'].annotation == typing.Optional[module.Bar[str]] | ||
assert module.Foo.model_fields['bar2'].annotation == typing.Union[int, module.Bar[float]] |
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.
These assertions are not valid anymore, as theBar[str]
class on the annotation is no longer the same that the one we create by callingmodule.Bar[str]
here (as it isn't cached anymore).
Coverage reportClick to see where and how coverage changed
This report was generated bypython-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.
Nice work. Happy to see this move across the line 👍
0b81063
intomainUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Change Summary
Fixes#10279, partiallyfixes#9887.
We avoid caching parametrized models when in the process of parametrizing another model, as the result of
BaseModel.__class_getitem__
can returnPydanticRecursiveRef
instances in this case. In the model core schema generation logic, we mutateFieldInfo
instances if the annotation wasn't evaluated yet, meaning we could set the annotation to some typing construct containing aPydanticRecursiveRef
, e.g. with:Because these
FieldInfo
instances come from themodel_fields
attribute of the model class, having the caching logic here can result in a parametrized model class with aFieldInfo
containingPydanticRecursiveRef
instances when we later parametrize a model (e.g.Model1[str]
).Note that is hopefully not a long term solution, as this doesn't fix what is an even simpler repro:#9969.
Related issue number
Checklist