From 345de2ee1dfb12c6314144c2b7ed6fb4a7a3cb7c Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 12 Feb 2012 17:14:34 -0500 Subject: - [bug] Fixed bug in new "autoload_replace" flag which would fail to preserve the primary key constraint of the reflected table. [ticket:2402] --- lib/sqlalchemy/engine/reflection.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/sqlalchemy/engine/reflection.py') 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) -- cgit v1.2.1