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 duplicate metadata on model rebuild#11902
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
codspeed-hqbot commentedMay 22, 2025 • 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#11902 willnot alter performanceComparing Summary
|
github-actionsbot commentedMay 22, 2025 • 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.
Coverage reportClick to see where and how coverage changed
This report was generated bypython-coverage-comment-action |
cloudflare-workers-and-pagesbot commentedMay 22, 2025 • 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: | cb10455 |
Status: | ✅ Deploy successful! |
Preview URL: | https://43275662.pydantic-docs.pages.dev |
Branch Preview URL: | https://11870-2-11-fix.pydantic-docs.pages.dev |
def _copy(self) -> Self: | ||
copied = copy(self) | ||
for attr_name in ('metadata', '_attributes_set', '_qualifiers'): | ||
# Apply "deep-copy" behavior on collections attributes: | ||
value = getattr(copied, attr_name).copy() | ||
setattr(copied, attr_name, value) | ||
return copied |
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.
We can't define a custom__copy__()
, because I couldn't find a way to delegate tocopy.copy()
and then apply the special case formetadata
,_attributes_set
and_qualifiers
.
The following could still be done:
def__copy__(self)->Self:cls=type(self)copied=cls()forattr_nameincls.__slots__:value=getattr(self,attr_name)ifattr_namein ('metadata','_attributes_set','_qualifiers'):# Apply "deep-copy" behavior on collections attributes:value=value.copy()setattr(copied,attr_name,value)returncopied
But this blows up on libraries (FastAPI/SQLModel) subclassingFieldInfo
(not the first time this is causing issues..) as we don't know which extra attributes are defined on these classes.
1b63218
intov2.11-fixesUh 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
This is a stripped down version of#11898, as a backport to 2.11. In 2.11, a change in the model rebuild logic surfaced an issue with
FieldInfo
being wrongly mutated and copied properly, resulting in a regression.#11898 is a proper refactor, but can't be fully backported as it would be too risky as a patch release.
Fixes (for 2.11)#11870.
Third-party tests output.
Related issue number
Checklist