Query.filter.options(load_only) difference in behaviour from sqlalchemy 1.4 onwards #11338
-
I am working on a legacy code base, currently using sqlalchemy 1.3 which I am trying to migrate to 1.4 first and then 2.0. To illustrate the point of this discussion, I have whittled things down to this code snippet:
That used to work in sqlalchemy 1.3, but in both 1.4 and 2.0, it generates an invalid sql query, ie:
Which triggers a database error such as:
I could re-write the expression above as a join instead of a IN clause, and in the example above that would be fairly straight-forward, but not so much in the actual legacy code base I need to migrate. My question is, why is the load_only option not being honoured, and is there a different syntax I could use to guarantee that the only one column is selected in the inner query I'm passing to the IN clause ? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
Beta Was this translation helpful? Give feedback.
-
Thank you, that does look like a rather simple/sensible solution. Because of the way my code base is organised (which is a bit more complex than my whittled down example), it's not that straight forward to make that change, however I found that this works too:
Are there any disadvantages to this later method that I should be wary of ? Thank you for all your help and the great work overall on sqlalchemy. |
Beta Was this translation helpful? Give feedback.
there's no need for that, simply write subqueries naturally, e.g.