diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-08-11 15:52:28 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-08-14 01:18:06 -0400 |
| commit | 1a990ee33239aa275567cb926a5b421b2087294b (patch) | |
| tree | edc023629e1f82a2d66e2a5ab6320681a0e91810 /test | |
| parent | e331da58a6d136aff824b43312424083090a7c90 (diff) | |
| download | sqlalchemy-1a990ee33239aa275567cb926a5b421b2087294b.tar.gz | |
Ensure Oracle index w/ col DESC etc. is reflected
Fixed bug where an index reflected under Oracle with an expression like
"column DESC" would not be returned, if the table also had no primary
key, as a result of logic that attempts to filter out the
index implicitly added by Oracle onto the primary key columns.
Reworked the "filter out the primary key index" logic in oracle
get_indexes() to be clearer.
This changeset also adds an internal check to ColumnCollection
to accomodate for the case of a column being added twice,
as well as adding a private _table argument to Index such that
reflection can specify the Table explicitly. The _table
argument can become part of public API in a later revision
or release if needed.
Change-Id: I745711e03b3e450b7f31185fc70e10d3823063fa
Fixes: #4042
Diffstat (limited to 'test')
| -rw-r--r-- | test/base/test_utils.py | 37 | ||||
| -rw-r--r-- | test/sql/test_metadata.py | 15 |
2 files changed, 51 insertions, 1 deletions
diff --git a/test/base/test_utils.py b/test/base/test_utils.py index b181a6fdb..9c36aeb9f 100644 --- a/test/base/test_utils.py +++ b/test/base/test_utils.py @@ -439,7 +439,7 @@ class ToListTest(fixtures.TestBase): ) -class ColumnCollectionTest(fixtures.TestBase): +class ColumnCollectionTest(testing.AssertsCompiledSQL, fixtures.TestBase): def test_in(self): cc = sql.ColumnCollection() @@ -496,6 +496,41 @@ class ColumnCollectionTest(fixtures.TestBase): eq_(ci._all_columns, [c1, c2a, c3, c2b]) eq_(list(ci), [c1, c2b, c3]) + def test_identical_dupe_add(self): + cc = sql.ColumnCollection() + + c1, c2, c3 = (column('c1'), + column('c2'), + column('c3')) + + cc.add(c1) + cc.add(c2) + cc.add(c3) + cc.add(c2) + + eq_(cc._all_columns, [c1, c2, c3]) + + self.assert_compile( + cc == [c1, c2, c3], + "c1 = c1 AND c2 = c2 AND c3 = c3" + ) + + # for iter, c2a is replaced by c2b, ordering + # is maintained in that way. ideally, iter would be + # the same as the "_all_columns" collection. + eq_(list(cc), [c1, c2, c3]) + + assert cc.contains_column(c2) + + ci = cc.as_immutable() + eq_(ci._all_columns, [c1, c2, c3]) + eq_(list(ci), [c1, c2, c3]) + + self.assert_compile( + ci == [c1, c2, c3], + "c1 = c1 AND c2 = c2 AND c3 = c3" + ) + def test_replace(self): cc = sql.ColumnCollection() diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py index 61fbbc57b..e204375f4 100644 --- a/test/sql/test_metadata.py +++ b/test/sql/test_metadata.py @@ -2255,6 +2255,21 @@ class ConstraintTest(fixtures.TestBase): i = Index('i', func.foo(t.c.x)) self._assert_index_col_x(t, i) + def test_index_no_cols_private_table_arg(self): + m = MetaData() + t = Table('t', m, Column('x', Integer)) + i = Index('i', _table=t) + is_(i.table, t) + eq_(list(i.columns), []) + + def test_index_w_cols_private_table_arg(self): + m = MetaData() + t = Table('t', m, Column('x', Integer)) + i = Index('i', t.c.x, _table=t) + is_(i.table, t) + + eq_(i.columns, [t.c.x]) + def test_inline_decl_columns(self): m = MetaData() c = Column('x', Integer) |
