﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
12242	DateQuerySet doesn't correctly mask extra selects	Russell Keith-Magee	nobody	"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.

"		closed	Database layer (models, ORM)	1.1		fixed			Unreviewed	0	0	0	0	0	0
