summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/schema.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-05-02 10:27:03 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2015-05-02 10:27:03 -0400
commit77db0ef6ac03d0f6f5622be373f7f85536924d3e (patch)
tree7d7bb0de993831b349a195711930e0f4a5d20bc8 /lib/sqlalchemy/sql/schema.py
parentb2196dd953e6313fcd688530aeeccfd013c61069 (diff)
downloadsqlalchemy-77db0ef6ac03d0f6f5622be373f7f85536924d3e.tar.gz
- 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
Diffstat (limited to 'lib/sqlalchemy/sql/schema.py')
-rw-r--r--lib/sqlalchemy/sql/schema.py24
1 files changed, 16 insertions, 8 deletions
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