multiple anonymous expressions in query()

Issue #3241 resolved
Mike Bayer repo owner created an issue

the error on 0.9 is better than in 1.0:

from sqlalchemy import *
from sqlalchemy.orm import *

e = create_engine('sqlite:///:memory:', echo='debug')
s = Session(e)

q1 = s.query(literal_column("1")).as_scalar()
q2 = s.query(literal_column("2")).as_scalar()
s.query(q1, q2).all()

0.9: sqlalchemy.exc.NoSuchColumnError: "Could not locate column in row for column '(SELECT 1)'" 1.0: File "/Users/classic/dev/sqlalchemy/lib/sqlalchemy/orm/loading.py", line 71, in instances rows = [keyed_tuple([proc(row) for proc in process]) TypeError: 'NoneType' object is not callable

Comments (4)

  1. Mike Bayer reporter

    the issue is in sqlite only due to _transform_select_for_nested_joins, as the ScalarSelect object isn't being copied to the result map when it is processed.

  2. Mike Bayer reporter

    here's a patch:

    diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py
    index 4d5bb94..434ebfd 100644
    --- a/lib/sqlalchemy/sql/elements.py
    +++ b/lib/sqlalchemy/sql/elements.py
    @@ -2779,6 +2779,10 @@ class Grouping(ColumnElement):
             return self
    
         @property
    +    def _key_label(self):
    +        return self._label
    +
    +    @property
         def _label(self):
             return getattr(self.element, '_label', None) or self.anon_label
    
  3. Mike Bayer reporter
    • Fixed bug regarding expression mutations which could express itself as a "Could not locate column" error when using :class:.Query to select from multiple, anonymous column entities when querying against SQLite, as a side effect of the "join rewriting" feature used by the SQLite dialect. fixes #3241

    → <<cset edec583b459e>>

  4. Mike Bayer reporter
    • Fixed bug regarding expression mutations which could express itself as a "Could not locate column" error when using :class:.Query to select from multiple, anonymous column entities when querying against SQLite, as a side effect of the "join rewriting" feature used by the SQLite dialect. fixes #3241

    → <<cset a54540383b9c>>

  5. Log in to comment