Code

Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#12242 closed (fixed)

DateQuerySet doesn't correctly mask extra selects

Reported by: russellm Owned by: nobody
Component: Database layer (models, ORM) Version: 1.1
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation:
Needs tests: Patch needs improvement:
Easy pickings: UI/UX:

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.

Attachments (0)

Change History (3)

comment:1 Changed 4 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to 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.

comment:2 Changed 4 years ago by russellm

(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 Changed 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.