#12242 closed (fixed)
DateQuerySet doesn't correctly mask extra selects
Reported by: | Russell Keith-Magee | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.1 |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
DateQuerySet doesn't interact well with extra.
Line 412 of sql/subqueries.sql explicitly clears *all* of the extra clause, including any Where clause.
However, any extra clause following the dates() clause will be left untouched.
The practical side effect of this is that there is a test in regressiontests/queries that will fail depending on database order. The test checks:
Item.objects.dates('created', 'day').extra(select={'a': 1}).query
will result in the SQL
SELECT DISTINCT (1) AS "a", DATE_TRUNC('day', "myapp_item"."created") FROM "myapp_item" ORDER BY 1 ASC
Which means that the ordering is done on (1), not on the date. It also means that any extra WHERE clause mentioned prior to the dates clause will not be processed.
The solution here should be to set the extra_select mask, rather than clearing the extra clause.
Change History (3)
comment:1 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
(In [11748]) Fixed #12242 -- Corrected a problem with masking extra selects() in a DateQuerySet. Thanks to Alex Gaynor for his help debugging this one.