Commit d589082
Fixed PrivateAttr defaults lost when loading from database (#149)
When SQLAlchemy reconstructs a model instance from a database query
(bypassing __init__), it goes through __new__ which calls
init_pydantic_private_attrs(). That function was setting
__pydantic_private__ = None instead of initializing it with the
private attribute defaults. This caused AttributeError when accessing
PrivateAttr fields on database-loaded instances.
The fix introspects the class's __private_attributes__ dict and calls
get_default() on each entry, mirroring what Pydantic's own __init__
does.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 530c268 commit d589082
1 file changed
+12
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
98 | 109 | | |
99 | 110 | | |
100 | 111 | | |
| |||
0 commit comments