[Sqlalchemy-tickets] Issue #3531: bind param replacement in join_condition() doesn't work for type_
Brought to you by:
zzzeek
|
From: Mike B. <iss...@bi...> - 2015-09-15 19:52:54
|
New issue 3531: bind param replacement in join_condition() doesn't work for type_coerce https://bitbucket.org/zzzeek/sqlalchemy/issues/3531/bind-param-replacement-in-join_condition Mike Bayer: type_coerce makes its decision about the thing it is processing when created. if a bindparam, the type is changed. otherwise, a label() is produced. However this fails for this : ``` #!python from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class CastToIntegerType(TypeDecorator): impl = String def column_expression(self, col): return cast(col, Integer) def bind_expression(self,col): return cast(col, String) class Person(Base): __tablename__ = 'person' id = Column('id_string', CastToIntegerType, primary_key=True) pets = relationship('Pets', primaryjoin='foreign(Pets.person_id)==type_coerce(Person.id, Integer)') class Pets(Base): __tablename__ = 'pets' id = Column('id', Integer, primary_key=True) person_id = Column('person_id', Integer, ForeignKey('person.id_string'), primary_key=True) e = create_engine("sqlite://", echo=True) Base.metadata.create_all(e) s = Session(e) s.add_all([Person(id="5", pets=[Pets(id="1")])]) s.commit() p1 = s.query(Person).first() p1.pets ``` because we are creating bindparam after the fact - there's no actual TypeCoerce construct here so when we see that Label, we don't know anything that there was a type coerce. We'd need to build some new construct. |