Can ORM object attributes be computed by a TextClause at add time #11379
-
Hi! For very unfortunate reasons, I have some complex ID assigning logic implemented in SQL. obj = ORMObject()
obj.obj_id = text("1 + 2")
db.session.add(obj) The above appears to work, but fails to type-check: Is this supported? TIA PS: I realized just a bit ago that I can probably use the query builder rather than a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
this pattern is fine, to deal w/ the typing use |
Beta Was this translation helpful? Give feedback.
the text() thing is usually going to work almost anywhere, but for a column expression the
literal_column()
is more appropriate. but if you have the bound parameters in there, there's not a good pattern for that right now, maybetext(..).columns(Integer).scalar_subquery()