summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/util.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-09-06 12:45:53 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-09-06 13:17:24 -0400
commitfc48050e5d0c56fc5a6cd85679859e71961c59eb (patch)
tree78ade9f3586e12239023b2aa95510c653a004dd4 /lib/sqlalchemy/sql/util.py
parent5c39ef565bb63e4412c3c3d0e87330373c8926ce (diff)
downloadsqlalchemy-fc48050e5d0c56fc5a6cd85679859e71961c59eb.tar.gz
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
Diffstat (limited to 'lib/sqlalchemy/sql/util.py')
-rw-r--r--lib/sqlalchemy/sql/util.py23
1 files changed, 19 insertions, 4 deletions
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):