- changed status to resolved
ForeignKeyConstraint.columns - WAT
Issue #3243
resolved
The ".columns" collection is first off not a ColumnCollection, and secondly it is a list that is either of strings or columns, depending on factors that are in a practical sense arbitrary, which is ridiculous. This collection should either not be there at all, or just changed to be a ColumnCollection. Hitting it will just invoke the FK. Some other accessor should be added that gives us the column names in the absense of the FK constraint actually being set up.
from sqlalchemy import Integer, Column, Table, MetaData, \
ForeignKeyConstraint, ForeignKey
m = MetaData()
t1 = Table(
't1', m,
Column('x', Integer, primary_key=True)
)
t2 = Table(
't2', m,
Column('y', Integer, primary_key=True),
Column('z1', Integer, ForeignKey('t1.x')),
Column('z2', Integer)
)
fk1 = [
const for const in t2.constraints
if isinstance(const, ForeignKeyConstraint)][0]
fk2 = ForeignKeyConstraint(['z2'], ['t1.x'])
# keys are Column objects, OK
assert isinstance(fk1.columns[0], Column)
# WAT
assert isinstance(fk2.columns[0], str)
t2.append_constraint(fk2)
# WAT
assert isinstance(fk2.columns[0], str)
Comments (1)
-
reporter - Log in to comment
.ForeignKeyConstraint.columns
collection has been made consistent; this attribute is now a :class:.ColumnCollection
like that of all other constraints and is initialized at the point when the constraint is associated with a :class:.Table
. fixes#3243→ <<cset 212d93366d1c>>