#12886: .aggregate() does not honour sliced queryset
--------------------------------------+-------------------------------------
Reporter: [email protected] | Owner:
Status: new | Milestone:
Component: ORM aggregation | Version: 1.2-beta
Resolution: | Keywords:
Stage: Accepted | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
--------------------------------------+-------------------------------------
Comment (by gruszczy):
I have managed to patch this, but encountered larger problem, that I have
problems with. I have added following test to
modeltests/aggregation/tests.py:
{{{
def test_join_annotate_aggregate(self):
vals =
Book.objects.all().annotate().aggregate(Max("authors__age"))
self.assertEqual(len(vals), 1)
self.assertEqual(vals["authors__age__max"], 57)
}}}
and it causes following exception:
{{{
======================================================================
ERROR: test_join_annotate_aggregate
(modeltests.aggregation.tests.BaseAggregateTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File
"/home/gruszczy/Programy/django/tests/modeltests/aggregation/tests.py",
line 21, in test_join_annotate_aggregate
vals = Book.objects.all().annotate().aggregate(Max("authors__age"))
File "/home/gruszczy/Programy/django/django/db/models/query.py", line
312, in aggregate
return query.get_aggregation(using=self.db)
File "/home/gruszczy/Programy/django/django/db/models/sql/query.py",
line 366, in get_aggregation
result = query.get_compiler(using).execute_sql(SINGLE)
File "/home/gruszczy/Programy/django/django/db/models/sql/compiler.py",
line 729, in execute_sql
cursor.execute(sql, params)
File
"/home/gruszczy/Programy/django/django/db/backends/sqlite3/base.py", line
200, in execute
return Database.Cursor.execute(self, query, params)
DatabaseError: no such column: T5.age
}}}
Generated SQL looks like this:
{{{
SELECT "aggregation_book"."id" AS "id", "aggregation_book"."isbn" AS
"isbn", "aggregation_book"."name" AS "name", "aggregation_book"."pages" AS
"pages", "aggregation_book"."rating" AS "rating",
"aggregation_book"."price" AS "price", "aggregation_book"."contact_id" AS
"contact_id",
"aggregation_book"."publisher_id" AS "publisher_id",
"aggregation_book"."pubdate" AS "pubdate" FROM "aggregation_book" LEFT
OUTER JOIN
"aggregation_book_authors" ON ("aggregation_book"."id" =
"aggregation_book_authors"."book_id") LEFT OUTER JOIN "aggregation_author"
T5 ON
("aggregation_book_authors"."author_id" = T5."id") GROUP BY
"aggregation_book"."id", "aggregation_book"."isbn",
"aggregation_book"."name",
"aggregation_book"."pages", "aggregation_book"."rating",
"aggregation_book"."price", "aggregation_book"."contact_id",
"aggregation_book"."publisher_id", "aggregation_book"."pubdate"
}}}
I am posting my partial patch with tests, so maybe someone could direct
me, where I should go from here and how can I solve the encountered bug.
--
Ticket URL: <http://code.djangoproject.com/ticket/12886#comment:4>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.