Address case where model_construct on a class which defines model_post_init fails with AttributeError: __pydantic_private__ when subsequently model_copy'd#9168
Conversation
CodSpeed Performance ReportMerging #9168 will not alter performanceComparing Summary
|
sydney-runkle
left a comment
There was a problem hiding this comment.
Looking good, just requested some minor changes!
|
Made another push which uses a local |
|
Ah, I see. Let's go with your initial approach then (it feels a bit cleaner to me). I'll go ahead and approve - we can merge once you revert back to that approach. Thanks a bunch - looking forward to merging soon! |
sydney-runkle
left a comment
There was a problem hiding this comment.
As noted above -- approved, will merge when you revert back to your initial approach with the hasattr checks followed by the direct attribute accesses (thanks for pointing out, we already use that pattern in model_construct
|
Changes have been reverted to the hasattr() followed by direct attribute access, also reverting ALL changes in |
|
Please review and merge, or let me know if anything else is needed here. And, finally, THANKS for pydantic - a great solution to such a core problem :) |
|
Looks fantastic. Thank you for your contribution!! |
Change Summary
See detail as reported in Issue #9122
Note: this patch specifically addresses the handling of
__pydantic_private__in__copy__,__deepcopy__and__eq__. It does not address usage in several other places in main.py including:__{get,set,del}attr__,__{get,set}state__. It was unclear whether these were required, as eventually the model created bymodel_constructwill in fact have__pydantic_private__set (possibly toNone).:## Related issue number: #9122
Checklist
Please Review
Fix #9122
Selected Reviewer: @alexmojaki