From 77db0ef6ac03d0f6f5622be373f7f85536924d3e Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 2 May 2015 10:27:03 -0400 Subject: - Fixed bug in enhanced constraint-attachment logic introduced in :ticket:`3341` where in the unusual case of a constraint that refers to a mixture of :class:`.Column` objects and string column names at the same time, the auto-attach-on-column-attach logic will be skipped; for the constraint to be auto-attached in this case, all columns must be assembled on the target table up front. Added a new section to the migration document regarding the original feature as well as this change. fixes #3411 --- lib/sqlalchemy/sql/schema.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index bbbd28b4d..e6d1d8858 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -2397,22 +2397,30 @@ class ColumnCollectionMixin(object): c for c in self._pending_colargs if isinstance(c, Column) ] + cols_w_table = [ c for c in col_objs if isinstance(c.table, Table) ] + cols_wo_table = set(col_objs).difference(cols_w_table) if cols_wo_table: + # feature #3341 - place event listeners for Column objects + # such that when all those cols are attached, we autoattach. assert not evt, "Should not reach here on event call" - def _col_attached(column, 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) - return + # issue #3411 - don't do the per-column auto-attach if some of the + # columns are specified as strings. + 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) + self._cols_wo_table = cols_wo_table + for col in cols_wo_table: + col._on_table_attach(_col_attached) + return columns = cols_w_table -- cgit v1.2.1