consider column.key as primary target in result proxy
Issue #2397
resolved
behavioral change following from #2392:
from sqlalchemy import *
e = create_engine("sqlite://")
metadata = MetaData(e)
keyed1 = Table('keyed1', metadata,
Column("a", CHAR(2), key="b"),
Column("c", CHAR(2), key="q")
)
keyed2 = Table('keyed2', metadata,
Column("a", CHAR(2)),
Column("b", CHAR(2)),
)
metadata.create_all()
keyed1.insert().execute(dict(b="a1", q="c1"))
keyed2.insert().execute(dict(a="a2", b="b2"))
row = select([keyed2](keyed1,)).execute().first()
# current
try:
row.a
assert False
except:
pass
assert row.b == 'b2'
# change:
#assert row.a == 'a2'
# would raise
#assert row.b == 'a1'
s = keyed1.select().apply_labels()
# current:
s.c.keyed1_a
# attribute error
try:
s.c.keyed1_b
assert False
except:
pass
# change:
# OK
#s.c.keyed1_b
# would raise
#s.c.keyed1_a
Comments (5)
-
reporter -
reporter so that's attached. I'd like to leave "key" out of the SQL so that there are no issues if someone is using weird keys with unicode, other characters, etc.
-
reporter 0.8 branch at 9b73e997b2325018555268e1f1069e88e80fdb85
-
reporter - changed status to resolved
-
reporter - removed milestone
Removing milestone: 0.8.0b1 (automated comment)
- Log in to comment
current leaning here is to fix "select.apply_labels()" to use "select.c.tablename_colkey" for the exported key, but otherwise not use any labeling in the SELECT statement itself, that is a labeled name comes out as "tablename_colname" in the SQL but "tablename_colkey" in Python. The column name still remains the primary target. Putting the "key" into the SQL doesn't seem worth it.