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 /test/engine | |
| 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 'test/engine')
| -rw-r--r-- | test/engine/test_reflection.py | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/test/engine/test_reflection.py b/test/engine/test_reflection.py index 62568eb4a..869fd63e5 100644 --- a/test/engine/test_reflection.py +++ b/test/engine/test_reflection.py @@ -1,7 +1,8 @@ import unicodedata import sqlalchemy as sa from sqlalchemy import schema, inspect -from sqlalchemy import MetaData, Integer, String +from sqlalchemy import MetaData, Integer, String, Index, ForeignKey, \ + UniqueConstraint from sqlalchemy.testing import ( ComparesTables, engines, AssertsCompiledSQL, fixtures, skip) @@ -201,6 +202,39 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): assert t4.c.z.type._type_affinity is String assert t4.c.q is old_q + @testing.provide_metadata + def test_extend_existing_reflect_all_dont_dupe_index(self): + m = self.metadata + d = Table( + "d", m, Column('id', Integer, primary_key=True), + Column('foo', String(50)), + Column('bar', String(50)), + UniqueConstraint('bar') + ) + Index("foo_idx", d.c.foo) + Table( + "b", m, Column('id', Integer, primary_key=True), + Column('aid', ForeignKey('d.id')) + ) + m.create_all() + + m2 = MetaData() + m2.reflect(testing.db, extend_existing=True) + + eq_( + len([idx for idx in m2.tables['d'].indexes + if idx.name == 'foo_idx']), + 1 + ) + if testing.requires.\ + unique_constraint_reflection_no_index_overlap.enabled: + eq_( + len([ + const for const in m2.tables['d'].constraints + if isinstance(const, UniqueConstraint)]), + 1 + ) + @testing.emits_warning(r".*omitted columns") @testing.provide_metadata def test_include_columns_indexes(self): |
