[Sqlalchemy-tickets] [sqlalchemy] #2845: Query.group_by() ignores arguments
Brought to you by:
zzzeek
|
From: sqlalchemy <mi...@zz...> - 2013-10-18 10:36:54
|
#2845: Query.group_by() ignores arguments
--------------------+-----------------------------------------
Reporter: dwt | Owner: zzzeek
Type: defect | Status: new
Priority: medium | Milestone:
Component: orm | Severity: no triage selected yet
Keywords: | Progress State: awaiting triage
--------------------+-----------------------------------------
Hi there,
I just spent an hour to debug why group_by was ignored for a query I was
transforming, so I gather it's worth it to spend some more time to report
a bug. We are using version 0.7.x so there may have been changes since,
but I wasn't yet able to invest the time to create a testcase that
reproduces this.
Here's what happens. Using the ORM I transform a query like this:
{{{
query =
statistics.track_items_for_topics_in_date_range_query([topic],
early_cutoff, late_cutoff)
from sqlalchemy.sql import func
query = query.with_entities(TrackItem.question_id,
TrackItem.user_id,
func.max(TrackItem.creation_time).label('max_creation_time'))
query = query.group_by(TrackItem.question, TrackItem.user)
}}}
The problem/workaround is to not use the objects in the group_by() but
instead the _id suffixes to tell sqlalchemy that it should group by the
ids instead.
Now what happens if you don't know/see this is that the group_by() call is
just ignored and the query is the exact same query after the call as it
was before hand.
Which is, uhm, a bit hard to debug. :)
--
Ticket URL: <http://www.sqlalchemy.org/trac/ticket/2845>
sqlalchemy <http://www.sqlalchemy.org/>
The Database Toolkit for Python
|