[Sqlalchemy-tickets] Issue #3188: regression in 0.9's "order by collapse" logic (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
|
From: Mike B. <iss...@bi...> - 2014-09-06 22:18:27
|
New issue 3188: regression in 0.9's "order by collapse" logic https://bitbucket.org/zzzeek/sqlalchemy/issue/3188/regression-in-09s-order-by-collapse-logic Mike Bayer: seems to be non-deterministic ``` #!python from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class C(Base): __tablename__ = 'c' id = Column(Integer, primary_key=True) a_id = Column(ForeignKey('a.id')) b_id = Column(ForeignKey('b.id')) class B(Base): __tablename__ = 'b' id = Column(Integer, primary_key=True) B.b = column_property( select([func.max(C.id)]).where(C.b_id == B.id).correlate(B) ) b1 = aliased(B) sess = Session() #print sess.query(B, b1).order_by(B.b) print sess.query(B, b1).order_by(b1.b) ``` output, based on if you uncomment that one query, for the *second* query, is: ``` #!sql SELECT b.id AS b_id, (SELECT max(c.id) AS max_1 FROM c WHERE c.b_id = b.id) AS anon_1, b_1.id AS b_1_id, (SELECT max(c.id) AS max_2 FROM c WHERE c.b_id = b_1.id) AS anon_2 FROM b, b AS b_1 ORDER BY anon_1 ``` e.g. it is ordering by the wrong expression. there's a lot going on with order_by right now so im not sure this can be in 0.9, will need to see if something can be backported. |