Replies: 1 comment 1 reply
-
Came across this while searching and figured I'd answer. This seems to allow models with partially matching fields to be constructed into a new model. Basically what I had was
Same logic is discussed a litter more in detail here https://docs.pydantic.dev/latest/api/config/#pydantic.config.ConfigDict.from_attributes . |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Looking at the API docs for
model_validate
, it says that function "Validate a pydantic model instance", which isn't terribly helpful, but I understand that it roughly "gets model field values from the attributes of the given object".However what then does
from_attributes
actually do? By default it isNone
, so I assume that evaluates toFalse
, but it still seems to get the values from objects regardless. Indeed, setting it true or false doesn't seem to actually change anything, and in any case if the function does not get the model's field values from the attributes of the given object when it is set to false, where else does it get them from?Beta Was this translation helpful? Give feedback.
All reactions