On Tue, Jun 24, 2014 at 3:35 PM, Mike Bayer <mike...@zzzcomputing.com>
wrote:

>
> On 6/23/14, 8:09 PM, Ken Lareau wrote:
> >
> >     if apptier:
> >         subq = (
> >             Session.query(
> >                 Package.pkg_name,
> >                 Package.version,
> >                 Package.revision,
> >                 AppDefinition.app_type,
> >                 AppDeployment.environment
> >             ).join(Deployment)
> >              .join(AppDeployment)
> >              .join(AppDefinition)
> >              .filter(Package.pkg_name == package_name)
> >              .filter(AppDeployment.environment == env)
> >              .filter(AppDeployment.status != 'invalidated'))
> >
> >         [...]
> >
> >         # The actual column name must be used in the subquery
> >         # usage below; DB itself should be corrected
> >         versions = (Session.query(subq.c.appType,
> >                     subq.c.version,
> >                     subq.c.revision)
> >                     .group_by(subq.c.appType, subq.c.environment)
> >                     .all())
> >
> > The parts in the subquery work fine, but the access of the 'column'
> > in the final query leads to this:
> >
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in <module>
> >   File "/home/klareau/repos/git/tagopsdb/tagopsdb/deploy/deploy.py",
> > line 234, in find_deployed_version
> >     .group_by(subq.c.appType, subq.c.environment)
> >   File
> >
> "/home/klareau/.virtualenvs/tds/lib/python2.6/site-packages/sqlalchemy/util/_collections.py",
> > line 174, in __getattr__
> >     raise AttributeError(key)
> > AttributeError: environment
> >
> > This is not completely surprising, but I'm uncertain as the best way
> > to fix this... help? :)
> nothing is obviously wrong, assuming you are calling "subquery()" on
> subq at the end.  It will be a select() construct which will have a
> column called ".environment" on the .c. collection because
> AppDeployment.environment is present.   Can't say why this attribute is
> not here without full details.
>
>
Oops there were some additional filters I left out, but this is added
before the final query:

subq = (subq.order_by(AppDeployment.realized.desc())
                    .subquery(name='t_ordered'))

Not sure why it isn't working, but today my coworker an I massively
rewrote one of the other methods to avoid this same issue, so maybe
we should try the same for this one... though it would be nice to know
what I goofed here, but not sure what additional information I can
give that would help offhand...

-- 
- Ken Lareau

-- 
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