From: Mike Bayer Date: Thu, 24 Dec 2015 03:59:44 +0000 (-0500) Subject: - Fixed an assertion that would raise somewhat inappropriately X-Git-Tag: rel_1_1_0b1~84^2~66 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c7d6c667b53d96a65e0dedcb83c098e03d4c7453;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Fixed an assertion that would raise somewhat inappropriately if a :class:`.Index` were associated with a :class:`.Column` that is associated with a lower-case-t :class:`.TableClause`; the association should be ignored for the purposes of associating the index with a :class:`.Table`. fixes #3616 --- diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst index 0d9f997f99..83a57ba7cf 100644 --- a/doc/build/changelog/changelog_11.rst +++ b/doc/build/changelog/changelog_11.rst @@ -21,6 +21,16 @@ .. changelog:: :version: 1.1.0b1 + .. change:: + :tags: bug, sql + :tickets: 3616 + + Fixed an assertion that would raise somewhat inappropriately + if a :class:`.Index` were associated with a :class:`.Column` that + is associated with a lower-case-t :class:`.TableClause`; the + association should be ignored for the purposes of associating + the index with a :class:`.Table`. + .. change:: :tags: bug, orm :tickets: 3601 diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index 42dbe72b2d..b244d746c3 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -2498,9 +2498,13 @@ class ColumnCollectionMixin(object): has_string_cols = set(self._pending_colargs).difference(col_objs) if not has_string_cols: def _col_attached(column, table): - cols_wo_table.discard(column) - if not cols_wo_table: - self._check_attach(evt=True) + # this isinstance() corresponds with the + # isinstance() above; only want to count Table-bound + # columns + if isinstance(table, Table): + cols_wo_table.discard(column) + if not cols_wo_table: + self._check_attach(evt=True) self._cols_wo_table = cols_wo_table for col in cols_wo_table: col._on_table_attach(_col_attached) diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py index d4039a5fec..bbc318421e 100644 --- a/test/sql/test_metadata.py +++ b/test/sql/test_metadata.py @@ -2068,6 +2068,13 @@ class IndexTest(fixtures.TestBase): t.append_constraint, idx ) + def test_column_associated_w_lowercase_table(self): + from sqlalchemy import table + c = Column('x', Integer) + table('foo', c) + idx = Index('q', c) + is_(idx.table, None) # lower-case-T table doesn't have indexes + class ConstraintTest(fixtures.TestBase):