diff options
Diffstat (limited to 'lib/sqlalchemy/sql')
| -rw-r--r-- | lib/sqlalchemy/sql/expression.py | 19 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/util.py | 6 |
2 files changed, 17 insertions, 8 deletions
diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 56629a6ca..812c70c2d 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -2925,8 +2925,6 @@ class CompoundSelect(_SelectBaseMixin, FromClause): else: self.selects.append(s) - self._col_map = {} - _SelectBaseMixin.__init__(self, **kwargs) for s in self.selects: @@ -2942,11 +2940,15 @@ class CompoundSelect(_SelectBaseMixin, FromClause): yield c def _proxy_column(self, column): - selectable = column.table - col_ordering = self._col_map.get(selectable, None) - if col_ordering is None: - self._col_map[selectable] = col_ordering = [] - + if not hasattr(self, '_col_map'): + self._col_map = dict([(s, []) for s in self.selects]) + for s in self.selects: + for c in s.c + [s.oid_column]: + self._col_map[c] = s + + selectable = self._col_map[column] + col_ordering = self._col_map[selectable] + if selectable is self.selects[0]: if self.use_labels: col = column._make_proxy(self, name=column._label) @@ -2962,8 +2964,9 @@ class CompoundSelect(_SelectBaseMixin, FromClause): def _copy_internals(self, clone=_clone): self._clone_from_clause() - self._col_map = {} self.selects = [clone(s) for s in self.selects] + if hasattr(self, '_col_map'): + del self._col_map for attr in ('_order_by_clause', '_group_by_clause'): if getattr(self, attr) is not None: setattr(self, attr, clone(getattr(self, attr))) diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index 70a1dcc96..9954811d6 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -152,6 +152,12 @@ class AbstractClauseProcessor(object): This class implements its own visit-and-copy strategy but maintains the same public interface as visitors.ClauseVisitor. + + The convert_element() method receives the *un-copied* version of each element. + It can return a new element or None for no change. If None, the element + will be cloned afterwards and added to the new structure. Note this is the + opposite behavior of visitors.traverse(clone=True), where visitors receive + the cloned element so that it can be mutated. """ __traverse_options__ = {'column_collections':False} |
