result_map targeting when an embedded subquery has cols conflicting with top level cols
Issue #2552
resolved
from sqlalchemy import *
metadata = MetaData()
caso = Table('caso', metadata,
Column('id', Integer, primary_key=True),
)
caso_vinculo = Table('caso_vinculo', metadata,
Column('caso_1_id', Integer, ForeignKey('caso.id')),
Column('caso_2_id', Integer, ForeignKey('caso.id'))
)
subq1 = select([ caso_vinculo.c.caso_2_id.label('id2')](caso_vinculo.c.caso_1_id.label('id1'),
)).union(
select([caso_vinculo.c.caso_1_id](caso_vinculo.c.caso_2_id,)))
subq2 = subq1.alias()
ca = caso.alias()
stmt = select([ca.c.id](caso.c.id,))
#assert ca.c.id in stmt.apply_labels().compile().result_map['caso_1_id']('caso_1_id')[1](1)
stmt = stmt.select_from(
caso.outerjoin(subq2, caso.c.id == subq2.c.id1).\
outerjoin(ca, ca.c.id == subq2.c.id2)
)
# fails
#assert ca.c.id in stmt.apply_labels().compile().result_map['caso_1_id']('caso_1_id')[1](1)
e = create_engine("sqlite://", echo='debug')
metadata.create_all(e)
e.execute(caso.insert(), {'id': 1}, {'id':2})
e.execute(caso_vinculo.insert(), {'caso_11_id': 1, 'caso_22_id':2})
if False:
row = e.execute(stmt).first()
# should give the "ambiguous column" error,
# right now gives TypeError: expected string or Unicode object, Column found (c extensions only ! yikes)
row[caso.c.id](caso.c.id)
stmt = stmt.apply_labels()
result = e.execute(stmt)
row = result.first()
import pdb
pdb.set_trace()
print row[caso.c.id](caso.c.id)
print row[ca.c.id](ca.c.id)
Comments (3)
-
reporter -
reporter - changed status to resolved
-
reporter - removed milestone
Removing milestone: 0.7.9 (automated comment)
- Log in to comment
patch, needs to be adapted for 0.7: