summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/engine/reflection.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-02-12 17:14:34 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2012-02-12 17:14:34 -0500
commit345de2ee1dfb12c6314144c2b7ed6fb4a7a3cb7c (patch)
tree4540d2c510e215123f5cbdb724bd34f889fa6673 /lib/sqlalchemy/engine/reflection.py
parentba0fb069d5e76e4fe3365765caa1239bfd7371cc (diff)
downloadsqlalchemy-345de2ee1dfb12c6314144c2b7ed6fb4a7a3cb7c.tar.gz
- [bug] Fixed bug in new "autoload_replace" flag
which would fail to preserve the primary key constraint of the reflected table. [ticket:2402]
Diffstat (limited to 'lib/sqlalchemy/engine/reflection.py')
-rw-r--r--lib/sqlalchemy/engine/reflection.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/sqlalchemy/engine/reflection.py b/lib/sqlalchemy/engine/reflection.py
index f5911f3b6..71d97e65f 100644
--- a/lib/sqlalchemy/engine/reflection.py
+++ b/lib/sqlalchemy/engine/reflection.py
@@ -317,7 +317,7 @@ class Inspector(object):
info_cache=self.info_cache, **kw)
return indexes
- def reflecttable(self, table, include_columns, exclude_columns=None):
+ def reflecttable(self, table, include_columns, exclude_columns=()):
"""Given a Table object, load its internal constructs based on introspection.
This is the underlying method used by most dialects to produce
@@ -414,9 +414,12 @@ class Inspector(object):
# Primary keys
pk_cons = self.get_pk_constraint(table_name, schema, **tblkw)
if pk_cons:
+ pk_cols = [table.c[pk]
+ for pk in pk_cons['constrained_columns']
+ if pk in table.c and pk not in exclude_columns
+ ] + [pk for pk in table.primary_key if pk.key in exclude_columns]
primary_key_constraint = sa_schema.PrimaryKeyConstraint(name=pk_cons.get('name'),
- *[table.c[pk] for pk in pk_cons['constrained_columns']
- if pk in table.c]
+ *pk_cols
)
table.append_constraint(primary_key_constraint)