-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Fix: Properly update private attrs with model_copy, update= and extra=allow
#12117
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
base: main
Are you sure you want to change the base?
Conversation
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
CodSpeed Performance ReportMerging #12117 will not alter performanceComparing Summary
|
model_copy, update= and extra=allowmodel_copy, update= and extra=allow
|
please review |
Viicos
left a comment
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.
In the case of extra="forbid" and extra="ignore", I think this was only accidentally working. In fact, things get inconsistent currently:
copy_working = original_working.model_copy(update={"_private": "private_copy"})
copy_working._private
#> private_copy
copy_working.__pydantic_private__
#> {'_private': 'private default'}Could you please update the PR to also take these cases into account? I think we need to also take into account private attributes for all extra cases.
But thinking about it, I'm afraid this will only be possible to do in
v3
model_copy() to be included in the extra fields.
Yep, done.
Could we change the behavior to continue to set the extra fields so that we fix the reported issue and maintain compatibility and have the v3 change be to remove the setting the extra fields? |
Do you have an example of how that would look like? I'm not sure I understand exactly what would be changed here. |
Change Summary
When using
model_copy'supdatefeature, private attributes are not correctly updated ifextra=allow.Related issue number
fix #12116
Checklist
Selected Reviewer: @Viicos