[1.7.x] 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 by2f35c6f10f
. Backport off0b358880a
from master
This commit is contained in:
parent
07c7925282
commit
4ce5ced230
|
@ -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:
|
||||
|
|
|
@ -2129,6 +2129,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'})
|
||||
|
|
Loading…
Reference in New Issue