This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Extend .model_validate
function, accepting some fields not in object
#9329
Labels
Initial Checks
Description
Why am I asking this:
I have a SQLAlchemy 2.0 query, which has User fields selected, as well as two aggregated fields, which are labeled. As, it is not possible to access those labelled attributes when used
scalars()
, I am forced to retrieve result asRow
object. The query also containsjoinedload
of other models, and they have corresponding field in pydantic schema. However, my two labelled aggregate data comes as separate, detached fromUser
model:As seen, skills and tools are not part of
User
object inRow
result, however, I want to pass them directly tomodel_validate
as a part ofUser
model. I can usefor
loop andsetattr
, however, I find that inefficient, especially If I have many aggregated/labelled fields inselect
.Affected Components
.model_dump()
and.model_dump_json()
model_construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: