Opened 15 years ago

Closed 15 years ago

Last modified 13 years ago

#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 Russell Keith-Magee, 15 years ago

Resolution: fixed
Status: newclosed

(In [11748]) Fixed #12242 -- Corrected a problem with masking extra selects() in a DateQuerySet. Thanks to Alex Gaynor for his help debugging this one.

comment:2 by Russell Keith-Magee, 15 years ago

(In [11749]) [1.1.X] Fixed #12242 -- Corrected a problem with masking extra selects() in a DateQuerySet. Thanks to Alex Gaynor for his help debugging this one.

Backport of r11748 from trunk.

comment:3 by Jacob, 13 years ago

milestone: 1.2

Milestone 1.2 deleted

Note: See TracTickets for help on using tickets.
Back to Top