consider column.key as primary target in result proxy

Issue #2397 resolved
Mike Bayer repo owner created an issue

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)

  1. Mike Bayer reporter

    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.

  2. Mike Bayer 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.

  3. Log in to comment