Fixed #23259 -- Corrected insertion order of extra() select_params

A regression caused queries to produce incorrect results for cases where
extra(select) is excluded by values() but included by extra(order_by)

The regression was caused by 2f35c6f10f.
This commit is contained in:
Rajiv Makhijani 2014-08-08 03:08:26 -07:00 committed by Anssi Kääriäinen
parent 12ad61aa9f
commit f0b358880a
2 changed files with 22 additions and 1 deletions

View File

@ -117,7 +117,7 @@ class SQLCompiler(object):
if self.query.distinct:
result.append(self.connection.ops.distinct_sql(distinct_fields))
params.extend(o_params)
result.append(', '.join(out_cols + self.ordering_aliases))
params.extend(s_params)
params.extend(self.ordering_params)
@ -146,6 +146,7 @@ class SQLCompiler(object):
if ordering:
result.append('ORDER BY %s' % ', '.join(ordering))
params.extend(o_params)
if with_limits:
if self.query.high_mark is not None:

View File

@ -2130,6 +2130,26 @@ class ValuesQuerysetTests(BaseQuerysetTest):
order_by=['value_minus_one'])
qs = qs.values('num')
def test_extra_select_params_values_order_in_extra(self):
# testing for 23259 issue
qs = Number.objects.extra(
select={'value_plus_x': 'num+%s'},
select_params=[1],
order_by=['value_plus_x'])
qs = qs.filter(num=72)
qs = qs.values('num')
self.assertQuerysetEqual(qs, [{'num': 72}], self.identity)
def test_extra_multiple_select_params_values_order_by(self):
# testing for 23259 issue
qs = Number.objects.extra(select=OrderedDict([('value_plus_x', 'num+%s'),
('value_minus_x', 'num-%s')]),
select_params=(72, 72))
qs = qs.order_by('value_minus_x')
qs = qs.filter(num=1)
qs = qs.values('num')
self.assertQuerysetEqual(qs, [], self.identity)
def test_extra_values_list(self):
# testing for ticket 14930 issues
qs = Number.objects.extra(select={'value_plus_one': 'num+1'})