column_property expression + order_by + the usual query limit/subquery thing producing double alias
Issue #2621
resolved
import sqlalchemy as sa
from sqlalchemy import orm
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Parent(Base):
__tablename__ = "parent"
id = sa.Column(sa.Integer, primary_key=True)
expr = orm.column_property(id > 0)
children = orm.relationship("Child", back_populates="parent")
class Child(Base):
__tablename__ = "child"
id = sa.Column(sa.Integer, primary_key=True)
parent_id = sa.Column(sa.Integer, sa.ForeignKey("parent.id"))
parent = orm.relationship("Parent", back_populates="children")
engine = sa.create_engine("postgres:///test", echo=True)
Base.metadata.create_all(engine)
session = orm.Session(bind=engine)
q = session.query(Parent)
q = q.options(orm.joinedload(Parent.children))
q = q.order_by(Parent.expr)
# Workaround:
#q = q.order_by(sa.case([1)]((Parent.expr,), else_=0))
q = q.limit(10)
q.all()
Comments (4)
-
reporter -
reporter ah.
> /Users/classic/dev/sqlalchemy/test.py(20)<module>() -> print set([expr2](expr1,)) (Pdb) hash(expr1) 269654473 (Pdb) hash(expr2) 269654473 (Pdb) expr1 == expr2 <sqlalchemy.sql.expression.BinaryExpression object at 0x1012e2a10> (Pdb) bool(expr1 == expr2) False (Pdb)
-
reporter - changed status to resolved
-
reporter - removed milestone
Removing milestone: 0.8.0final (automated comment)
- Log in to comment
here's some more succinct ways of looking at the bug:
so both outcomes aren't great, but at least the second one applies a different label. but this is just annotation. the whole point of annotation is that
__hash__
stays the same so not sure why the uniquing logic isn't working here.