summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/engine/reflection.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-08-28 17:25:44 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-08-28 17:25:44 -0400
commitfe66951f5de6a2b201dc3ecc2261f4f8b8888e9f (patch)
treeefe0e66dbd262ef473094514cc14fcc9854e464f /lib/sqlalchemy/engine/reflection.py
parent03c9b2df770385fc3b2b0acbdcb809c2239b67ef (diff)
downloadsqlalchemy-fe66951f5de6a2b201dc3ecc2261f4f8b8888e9f.tar.gz
Fixed bug where using the ``column_reflect`` event to change the ``.key``
of the incoming :class:`.Column` would prevent primary key constraints, indexes, and foreign key constraints from being correctly reflected. Also in 0.8.3. [ticket:2811]
Diffstat (limited to 'lib/sqlalchemy/engine/reflection.py')
-rw-r--r--lib/sqlalchemy/engine/reflection.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/lib/sqlalchemy/engine/reflection.py b/lib/sqlalchemy/engine/reflection.py
index 340af1abb..28494dc7d 100644
--- a/lib/sqlalchemy/engine/reflection.py
+++ b/lib/sqlalchemy/engine/reflection.py
@@ -433,7 +433,8 @@ class Inspector(object):
# table attributes we might need.
reflection_options = dict(
- (k, table.kwargs.get(k)) for k in dialect.reflection_options if k in table.kwargs)
+ (k, table.kwargs.get(k))
+ for k in dialect.reflection_options if k in table.kwargs)
schema = table.schema
table_name = table.name
@@ -458,8 +459,12 @@ class Inspector(object):
# columns
found_table = False
+ cols_by_orig_name = {}
+
for col_d in self.get_columns(table_name, schema, **tblkw):
found_table = True
+ orig_name = col_d['name']
+
table.dispatch.column_reflect(self, table, col_d)
name = col_d['name']
@@ -497,7 +502,9 @@ class Inspector(object):
sequence.increment = seq['increment']
colargs.append(sequence)
- col = sa_schema.Column(name, coltype, *colargs, **col_kw)
+ cols_by_orig_name[orig_name] = col = \
+ sa_schema.Column(name, coltype, *colargs, **col_kw)
+
table.append_column(col)
if not found_table:
@@ -507,9 +514,9 @@ class Inspector(object):
pk_cons = self.get_pk_constraint(table_name, schema, **tblkw)
if pk_cons:
pk_cols = [
- table.c[pk]
+ cols_by_orig_name[pk]
for pk in pk_cons['constrained_columns']
- if pk in table.c and pk not in exclude_columns
+ if pk in cols_by_orig_name and pk not in exclude_columns
]
pk_cols += [
pk
@@ -527,7 +534,11 @@ class Inspector(object):
fkeys = self.get_foreign_keys(table_name, schema, **tblkw)
for fkey_d in fkeys:
conname = fkey_d['name']
- constrained_columns = fkey_d['constrained_columns']
+ constrained_columns = [
+ cols_by_orig_name[c].key
+ if c in cols_by_orig_name else c
+ for c in fkey_d['constrained_columns']
+ ]
if exclude_columns and set(constrained_columns).intersection(
exclude_columns):
continue
@@ -567,5 +578,5 @@ class Inspector(object):
"Omitting %s KEY for (%s), key covers omitted columns." %
(flavor, ', '.join(columns)))
continue
- sa_schema.Index(name, *[table.columns[c] for c in columns],
+ sa_schema.Index(name, *[cols_by_orig_name[c] for c in columns],
**dict(unique=unique))