On Thu, Jun 26, 2014 at 5:57 AM, Mike Bayer <mike...@zzzcomputing.com>
wrote:

>
> On 6/25/14, 8:06 PM, Ken Lareau wrote:
>
> On Wed, Jun 25, 2014 at 6:28 AM, Mike Bayer <mike...@zzzcomputing.com>
> wrote:
>
>>
>> On 6/25/14, 2:26 AM, Ken Lareau wrote:
>>
>> 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...
>>
>>
>>  what are the names that are actually present on subq.c ?   "print
>> list(subq.c)" should give an indication.
>>
>>
> Adding that in to the method gave this:
>
> >>> deploy.find_deployed_version('tdstest', 'development', version='9',
> apptier=True)
> [Column('pkg_name', String(length=255), table=<t_ordered>,
> nullable=False), Column('version', String(length=63), table=<t_ordered>,
> nullable=False), Column('revision', String(length=63), table=<t_ordered>,
> nullable=False), Column('appType', String(length=100), table=<t_ordered>,
> nullable=False), <sqlalchemy.sql.elements.ColumnClause at 0x1d20e10;
> %(30521360 anon)s>]
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/home/klareau/repos/git/tagopsdb/tagopsdb/deploy/deploy.py", line
> 237, 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
>
> you need to put .label('environment') on that column before it finds its
> way into subq.  I dont have the mappings here to review.
>
> for the next go around please just provide a one-file example of the
> mapping plus the query, thanks.
>
> Do you desire the example to be fully functional, or just have the relevant
mapping and query?  We ran into the same issue with another query and
ended up completely reworking the code to avoid the subquery, but it in-
volves quite a bit of various mappings and I'm uncertain if it's the proper
way to move forward.  I could try to post the before/after here, but if it
needs to be able to to run standalone it may take me a bit of time to get
it into a fully workable state (given how extensive it is).


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