From: Mike Bayer Date: Wed, 28 Aug 2013 21:31:40 +0000 (-0400) Subject: plus some more adjustments for mysql, or in general if an Index refers to X-Git-Tag: rel_0_8_3~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2008344aab70a9152ed23adb2b4c768fcb6103a4;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git plus some more adjustments for mysql, or in general if an Index refers to in-python only cols --- diff --git a/lib/sqlalchemy/engine/reflection.py b/lib/sqlalchemy/engine/reflection.py index c1c546d843..4581248932 100644 --- a/lib/sqlalchemy/engine/reflection.py +++ b/lib/sqlalchemy/engine/reflection.py @@ -470,6 +470,8 @@ class Inspector(object): fkeys = self.get_foreign_keys(table_name, schema, **tblkw) for fkey_d in fkeys: conname = fkey_d['name'] + # look for columns by orig name in cols_by_orig_name, + # but support columns that are in-Python only as fallback constrained_columns = [ cols_by_orig_name[c].key if c in cols_by_orig_name else c @@ -514,5 +516,11 @@ class Inspector(object): "Omitting %s KEY for (%s), key covers omitted columns." % (flavor, ', '.join(columns))) continue - sa_schema.Index(name, *[cols_by_orig_name[c] for c in columns], + # look for columns by orig name in cols_by_orig_name, + # but support columns that are in-Python only as fallback + sa_schema.Index(name, *[ + cols_by_orig_name[c] if c in cols_by_orig_name + else table.c[c] + for c in columns + ], **dict(unique=unique)) diff --git a/test/engine/test_reflection.py b/test/engine/test_reflection.py index 5aa1f7a3da..84a317dd45 100644 --- a/test/engine/test_reflection.py +++ b/test/engine/test_reflection.py @@ -1425,11 +1425,13 @@ class ColumnEventsTest(fixtures.TestBase): 'to_reflect', cls.metadata, Column('x', sa.Integer, primary_key=True), + test_needs_fk=True ) cls.related = Table( 'related', cls.metadata, - Column('q', sa.Integer, sa.ForeignKey('to_reflect.x')) + Column('q', sa.Integer, sa.ForeignKey('to_reflect.x')), + test_needs_fk=True ) sa.Index("some_index", cls.to_reflect.c.x) cls.metadata.create_all(testing.db)