diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-11-23 09:14:02 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-11-23 10:31:56 -0500 |
commit | 55ad10370f9eb50795e136aac595193168982e92 (patch) | |
tree | 2571e7b7d844dec8cb22cf475188e3ec65cb3184 /lib/sqlalchemy/engine/reflection.py | |
parent | 868e98bf407175b016e9e5cbc95bcf0cc859362a (diff) | |
download | sqlalchemy-55ad10370f9eb50795e136aac595193168982e92.tar.gz |
Add _extend_on deduplicating set for metadata.reflect()
The "extend_existing" option of :class:`.Table` reflection would
cause indexes and constraints to be doubled up in the case that the parameter
were used with :meth:`.MetaData.reflect` (as the automap extension does)
due to tables being reflected both within the foreign key path as well
as directly. A new de-duplicating set is passed through within the
:meth:`.MetaData.reflect` sequence to prevent double reflection in this
way.
Change-Id: Ibf6650c1e76a44ccbe15765fd79df2fa53d6bac7
Fixes: #3861
Diffstat (limited to 'lib/sqlalchemy/engine/reflection.py')
-rw-r--r-- | lib/sqlalchemy/engine/reflection.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/sqlalchemy/engine/reflection.py b/lib/sqlalchemy/engine/reflection.py index 5d11bf990..d1c9a22ac 100644 --- a/lib/sqlalchemy/engine/reflection.py +++ b/lib/sqlalchemy/engine/reflection.py @@ -532,7 +532,8 @@ class Inspector(object): return self.dialect.get_check_constraints( self.bind, table_name, schema, info_cache=self.info_cache, **kw) - def reflecttable(self, table, include_columns, exclude_columns=()): + def reflecttable(self, table, include_columns, exclude_columns=(), + _extend_on=None): """Given a Table object, load its internal constructs based on introspection. @@ -553,6 +554,13 @@ class Inspector(object): in the reflection process. If ``None``, all columns are reflected. """ + + if _extend_on is not None: + if table in _extend_on: + return + else: + _extend_on.add(table) + dialect = self.bind.dialect schema = self.bind.schema_for_object(table) @@ -602,7 +610,7 @@ class Inspector(object): self._reflect_fk( table_name, schema, table, cols_by_orig_name, - exclude_columns, reflection_options) + exclude_columns, _extend_on, reflection_options) self._reflect_indexes( table_name, schema, table, cols_by_orig_name, @@ -692,7 +700,7 @@ class Inspector(object): def _reflect_fk( self, table_name, schema, table, cols_by_orig_name, - exclude_columns, reflection_options): + exclude_columns, _extend_on, reflection_options): fkeys = self.get_foreign_keys( table_name, schema, **table.dialect_kwargs) for fkey_d in fkeys: @@ -715,6 +723,7 @@ class Inspector(object): sa_schema.Table(referred_table, table.metadata, autoload=True, schema=referred_schema, autoload_with=self.bind, + _extend_on=_extend_on, **reflection_options ) for column in referred_columns: @@ -724,6 +733,7 @@ class Inspector(object): sa_schema.Table(referred_table, table.metadata, autoload=True, autoload_with=self.bind, schema=sa_schema.BLANK_SCHEMA, + _extend_on=_extend_on, **reflection_options ) for column in referred_columns: |