Skip to content

regression in 0.9's "order by collapse" logic #3188

@sqlalchemy-bot

Description

@sqlalchemy-bot

Migrated issue, originally created by Michael Bayer (@zzzeek)

seems to be non-deterministic

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions