Column property works in instance context, but produces bad SQL in class context.
Issue #2263
resolved
Certain ''column_properties'' result in bad SQL code generation in class context, when correlated against the table of the mapper where the ''column_property'' is on.
To reproduce:
Run attached script.
I only checked 0.6.8.
Comments (2)
-
repo owner -
repo owner - removed milestone
Removing milestone: 0.6.9 (automated comment)
- Log in to comment
I didn't notice this ticket since a milestone had been assigned, usually that's my job :)
A critical strategy to use when faced with issues like these is to watch the generated SQL. Turn on echo=True:
using that, we can see the SQL is incorrect as:
See anything missing ? There's no "transactions" in the FROM clause. Why might this be ? Because you're selecting from a SELECT statement where you've explicitly told it not to put "transactions" in this clause:
"correlate" means, "don't put 'transactions' in the FROM clause under any circumstances". You need to take that out:
query then auto-correlates as needed, or not - when the SQL expression is queried as-is, "transactions" is added to the FROM list normally:
another technique to keep in mind, you can get a similar result ("transactions" on the outside) by setting the FROM clause on the query explicitly:
result: