Thanks for the pointers and for checking.  I misidentified the problem in 
traverse.  It does eventually iterate down to just the columns in the call 
to _copy_internals.  So the problem boils down to the second thing I 
mentioned which is the require_embedded parameter being set to true when 
corresponding_column is called.  The selectable I'm using isn't just a 
simple alias.

I subclassed ClauseAdapter and rewrote replace so that corresponding_column 
is called with require_embedded=False 
(https://github.com/zzzeek/sqlalchemy/blob/699272e4dcb9aa71ebbc0d9487fb6de82d3abc2b/lib/sqlalchemy/sql/util.py#L656).
  
This seems to be working.

On Wednesday, May 9, 2018 at 12:28:28 AM UTC-7, Zac Goldstein wrote:
>
> I'm trying to use ClauseAdapter.traverse similar to how it's used in your 
> old blog post to substitute columns in arbitrary clauses with columns on a 
> different selectable that share an ancestor: 
> http://techspot.zzzeek.org/archive/2008/01/1/
>
> Even in a simple case using a BinaryExpression, 
> ClauseAdapter(selectable).traverse(binaryexpression) is simply returning 
> the expression.  When I looked at it with the debugger, it seems the 
> expression isn't being traversed, but rather it eventually feeds the entire 
> BinaryExpression object into corresponding_column and subsequently 
> returns the full expression since obviously the BinaryExpression can't be 
> matched to a particular column on the selectable.
>
> selectable.corresponding_column(binaryexpression.left) returns the 
> correct column, however 
> ClauseAdapter(selectable).traverse(binaryexpression.left) does not.  The 
> discrepancy is found in corresponding_column being called with 
> require_embedded=True during traverse, which is hardcoded.  I don't know 
> if this behavior causes the behavior I previously described with the 
> BinaryExpression being passed to corresponding_column, but it seemed 
> noteworthy.
>
> Any ideas for fixes or alternatives?
>
> Thanks
>
>
>
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to