Nicely formatted version: 
http://stackoverflow.com/questions/24930155/strange-error-after-sqlalchemy-update-list-object-has-no-attribute-all-colu

After updating to the most recent SQLAlchemy one of my slightly more 
complex query started to fail with an error inside SQLalchemy.

Here's a simplified version of my query:

    subquery = (select(['latitude'])
                .select_from(func.unnest(func.array_agg(Room.latitude))
                             .alias('latitude')).limit(1).as_scalar())
    Room.query.with_entities(Room.building, 
subquery).group_by(Room.building).all()

When executing it I get an error deep inside SQLAlchemy:


      File ".../sqlalchemy/sql/selectable.py", line 429, in columns
        self._populate_column_collection()
      File ".../sqlalchemy/sql/selectable.py", line 992, in 
_populate_column_collection
        for col in self.element.columns._all_columns:
    AttributeError: 'list' object has no attribute '_all_columns'

Inspecting it in a debugger shows me this:

    >>> self.element
    <sqlalchemy.sql.functions.Function at 0x7f72d4fcae50; unnest>
    >>> str(self.element)
    'unnest(array_agg(rooms.id))'
    >>> self.element.columns
    [<sqlalchemy.sql.functions.Function at 0x7f72d4fcae50; unnest>]

The problem started with SQLAlchemy 0.9.4; in 0.9.3 everything worked fine.

When running it in SQLAlchemy 0.9.3 the following query is executed (as 
expected):


    SELECT rooms.building AS rooms_building,
           (SELECT latitude
            FROM unnest(array_agg(rooms.latitude)) AS latitude
            LIMIT 1) AS anon_1
    FROM rooms
    GROUP BY rooms.building

Am I doing something wrong here or is it a bug in SQLAlchemy?




-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to