Extend .model_validate
function, accepting some fields not in object
#9339
Unanswered
mmzeynalli
asked this question in
Question
Replies: 1 comment 1 reply
-
Thanks for your question. Could you get your |
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
-
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 modeBeta Was this translation helpful? Give feedback.
All reactions