column targeting causes unhandled conflicts due to "label is the column" rule

Issue #2591 resolved
Mike Bayer repo owner created an issue
from sqlalchemy import *
from sqlalchemy.orm import Session

class MyType(TypeDecorator):
    impl = Integer

    def process_result_value(self, value, dialect):
        return (value,)

metadata = MetaData()
t = Table('user', metadata, Column('id', Integer))

e = create_engine("sqlite://", echo=True)

metadata.create_all(e)

e.execute(t.insert(), {'id':1})

s = Session(e)
row = s.\
            query(t.c.id, type_coerce(t.c.id, MyType).label('foo')).\
            filter(t.c.id == 1).first()

assert row == (1, (1,)), repr(row)

the incoming fix will break the long-standing rule that "c.label('x')" should target as "c". this isn't a behavior that's being relied upon by the ORM. There may be some users who are running slightly mis-formed select() queries into query.from_statement() who may hit this issue, but at the moment there's no way to target these two columns separately.

Comments (2)

  1. Log in to comment