> this would imply you're sending a class into a filter() expression or
> something similar (such as, MyClass.foo==SomeOtherClass).

I didn't understand at first, because the query in question

>>> Session.query(Project, func.count(Charge)).join(Project.allocations, 
>>> Allocation.charges).group_by(Charge.id).all()

has no filter() argument. But looking at the partial sql generated by
the above query revealed the only bind parameter:

>>> print Session.query(Project, func.count(Charge)).join(Project.allocations, 
>>> Allocation.charges).group_by(Charge.id)
SELECT projects.id AS projects_id, count(?) AS count_1
FROM projects JOIN allocations ON projects.id = allocations.project_id
JOIN charges ON allocations.id = charges.allocation_id GROUP BY
charges.id

It seems that func does not understand taking arguments of mapped
python objects. I don't even know that it should. In any case, using
an actual property/attribute/column fixed the problem:

>>> print Session.query(Project, 
>>> func.count(Charge.id)).join(Project.allocations, 
>>> Allocation.charges).group_by(Charge.id)
SELECT projects.id AS projects_id, count(charges.id) AS count_1
FROM projects JOIN allocations ON projects.id = allocations.project_id
JOIN charges ON allocations.id = charges.allocation_id GROUP BY
charges.id
>>> Session.query(Project, func.count(Charge.id)).join(Project.allocations, 
>>> Allocation.charges).group_by(Charge.id).all()
[]

Thank you for helping me find my (eventually obvious) problem.

On Oct 15, 8:19 pm, Michael Bayer <[EMAIL PROTECTED]> wrote:
> On Oct 15, 2008, at 6:19 PM, Jonathon Anderson wrote:
>
>
>
> > I keep getting an exception deep within sqlalchemy whenever I try to
> > select a bit of aggregate data using the Session (I'm using SA
> > 0.5.0rc2). For now, assume that my metadata/mappers are sensible,
> > because I can't get over the thought that I'm just doing something
> > simple wrong with the query, but if there's nothing obviously wrong
> > here, I'll post mappers, etc
>
> its interpreting a bind parameter as a callable unit and attempting to  
> call it.    Additionally the callable seems to be an uninstantiated  
> class.   The trace is occuring as you attempt to execute a Query.  So  
> this would imply you're sending a class into a filter() expression or  
> something similar (such as, MyClass.foo==SomeOtherClass).
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to