[Sqlalchemy-tickets] Issue #4367: aliased join leaks into any() / has(), only when using declarativ
Brought to you by:
zzzeek
From: Michael B. <iss...@bi...> - 2018-11-14 15:35:41
|
New issue 4367: aliased join leaks into any() / has(), only when using declarative https://bitbucket.org/zzzeek/sqlalchemy/issues/4367/aliased-join-leaks-into-any-has-only-when Michael Bayer: the tests we've had for years in https://github.com/zzzeek/sqlalchemy/blob/master/test/orm/test_query.py#L2382 fails on declarative only; the columns contain the "parententity" annotation when using declarative, only "parentmapper" when not. I have no idea what this is about. test: ``` #!python from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declared_attr Base = declarative_base() class C(Base): __tablename__ = 'c' id = Column(Integer, primary_key=True) class B(Base): __tablename__ = 'b' id = Column(Integer, primary_key=True) c_id = Column(ForeignKey(C.id)) c = relationship("C") s = Session() print( s.query(B).join(B.c, aliased=True).filter(B.c.has(C.id == 1)) ) ``` classical: ``` #!python from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declared_attr m = MetaData() c = Table( 'c', m, Column('id', Integer, primary_key=True) ) b = Table( 'b', m, Column('id', Integer, primary_key=True), Column('c_id', ForeignKey('c.id')) ) class C(object): pass class B(object): pass mapper(B, b, properties={ 'c': relationship(C) }) mapper(C, c) s = Session() print( s.query(B).join(B.c, aliased=True).filter(B.c.has(C.id == 1)) ) ``` outputs: ``` #!python [classic@photon2 sqlalchemy]$ python test2.py SELECT b.id AS b_id, b.c_id AS b_c_id FROM b JOIN c AS c_1 ON c_1.id = b.c_id WHERE EXISTS (SELECT 1 FROM c WHERE c_1.id = b.c_id AND c.id = :id_1) [classic@photon2 sqlalchemy]$ python test3.py SELECT b.id AS b_id, b.c_id AS b_c_id FROM b JOIN c AS c_1 ON c_1.id = b.c_id WHERE EXISTS (SELECT 1 FROM c WHERE c.id = b.c_id AND c.id = :id_1) ``` |