Combining multiple from_selfs and unmapped ColumnEntity doesn't work

Issue #1617 resolved
Former user created an issue

If you build a query, from_self() it, add a ColumnEntity like sql.func.count(), and then from_self() again, the second from_self() will fail to find the corresponding column for the ColumnEntity, resulting in the attached traceback. A test case is also attached as a patch against test_query.py. This kind of query construct is useful for constructing many-to-many histograms without having to use sql expression language, such as building a tag cloud from a set of arbitrary search results.

This behavior begins in r6402 (prior to that the test case passes). I'm not sure if it is intentional or not, however, since the query works without the first from_self(), I am guessing it's a bug.

I found a fix that essentially isolates the broken behavior and reverts to the pre-r6402 behavior for only that case. The better long-term patch would probably be to fix the FromClause.corresponding_column method so that it returns the right column for the aliased ColumnEntity, but I haven't been able to figure out the fix there.

Thanks, Scott Torborg

Comments (7)

  1. Former user Account Deleted

    Thanks, I guess my code is good at exposing sqlalchemy edge cases... maybe not such a good thing. Please don't hesitate to post if there's anything else I can do to help land stuff like this (more tests, different patch style, etc).

  2. Former user Account Deleted

    Ok, my teammate Mike managed to find a better fix here, that properly patches FromClause.corresponding_column() to do the right thing in the multiple-aliases case. The test case I posted earlier is wrong, included is a fixed test.

    Also, can you add storborg@mit.edu to the cc?

    Thanks, Scott

  3. Log in to comment