From fc48050e5d0c56fc5a6cd85679859e71961c59eb Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 6 Sep 2019 12:45:53 -0400 Subject: Adjustments to _copy_internals() We are looking to build a generalization of copy_internals(), so move out any special logic from these methods. Re-implement and clarify rationale for the Alias doesnt copy a TableClause rule as part of the adaption traversal, establish that we forgot to build out comparison and cache key for CTE, remove incomplete _copy_internals() from GenerativeSelect (it doesn't handle the order_by_clause or group_by_clause, so is incomplete) Change-Id: I95039f042503171aade4ba0fabc9b1598e3c49cf --- lib/sqlalchemy/sql/util.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'lib/sqlalchemy/sql/util.py') diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index dd2c7c1fb..fe83b163c 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -806,10 +806,25 @@ class ClauseAdapter(visitors.ReplacingCloningVisitor): return newcol def replace(self, col): - if isinstance(col, FromClause) and self.selectable.is_derived_from( - col - ): - return self.selectable + if isinstance(col, FromClause): + if self.selectable.is_derived_from(col): + return self.selectable + elif isinstance(col, Alias) and isinstance( + col.element, TableClause + ): + # we are a SELECT statement and not derived from an alias of a + # table (which nonetheless may be a table our SELECT derives + # from), so return the alias to prevent futher traversal + # or + # we are an alias of a table and we are not derived from an + # alias of a table (which nonetheless may be the same table + # as ours) so, same thing + return col + else: + # other cases where we are a selectable and the element + # is another join or selectable that contains a table which our + # selectable derives from, that we want to process + return None elif not isinstance(col, ColumnElement): return None elif self.include_fn and not self.include_fn(col): -- cgit v1.2.1