Joining to a union that has single column does not work.

Issue #1853 resolved
Former user created an issue

See attached script.

When doing a union of only one column such as session.query(user.id).union(session.query(user.id)), makes this query unjoinable to.

Works in 0.58 as expected Fails in 0.62

Tested in both postgres and sqlite.

Comments (6)

  1. Mike Bayer repo owner

    here's a patch:

    diff -r 10db67be5b783b94b59dd7cf039f8c322cf837c8 lib/sqlalchemy/orm/query.py
    --- a/lib/sqlalchemy/orm/query.py       Wed Jul 14 14:50:45 2010 -0400
    +++ b/lib/sqlalchemy/orm/query.py       Wed Jul 14 21:39:57 2010 -0400
    @@ -2622,7 +2622,9 @@
             return self.column.type
    
         def adapt_to_selectable(self, query, sel):
    -        _ColumnEntity(query, sel.corresponding_column(self.column))
    +        c = _ColumnEntity(query, sel.corresponding_column(self.column))
    +        c.entities = self.entities
    +        c.entity_zero = self.entity_zero
    
         def setup_entity(self, entity, mapper, adapter, from_obj,
                                     is_aliased_class, with_polymorphic):
    

    will have to work up some tests, also want to remember why annotations aren't getting transferred here.

  2. Mike Bayer repo owner

    and also, we need to produce an error of some kind if _joinpoint_zero() is returning None. i.e. fails:

    session.query(users_table.c.id).select_from(users_table).join(User)
    
  3. Log in to comment