diff --git a/django/db/models/query.py b/django/db/models/query.py
index 0210a79..2f0a4cf 100644
a
|
b
|
class ValuesQuerySet(QuerySet):
|
1021 | 1021 | self.aggregate_names = None |
1022 | 1022 | |
1023 | 1023 | self.query.select = [] |
1024 | | if self.extra_names is not None: |
1025 | | self.query.set_extra_mask(self.extra_names) |
| 1024 | extra_mask_names = self.extra_names + list(self.query.extra_order_by or []) |
| 1025 | if extra_mask_names is not None: |
| 1026 | self.query.set_extra_mask(extra_mask_names) |
1026 | 1027 | self.query.add_fields(self.field_names, True) |
1027 | 1028 | if self.aggregate_names is not None: |
1028 | 1029 | self.query.set_aggregate_mask(self.aggregate_names) |
… |
… |
class ValuesListQuerySet(ValuesQuerySet):
|
1097 | 1098 | def iterator(self): |
1098 | 1099 | if self.flat and len(self._fields) == 1: |
1099 | 1100 | for row in self.query.get_compiler(self.db).results_iter(): |
1100 | | yield row[0] |
| 1101 | yield row[len(self.query.extra_select_mask)] |
1101 | 1102 | elif not self.query.extra_select and not self.query.aggregate_select: |
1102 | 1103 | for row in self.query.get_compiler(self.db).results_iter(): |
1103 | 1104 | yield tuple(row) |
diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py
index 71ac107..4fd6717 100644
a
|
b
|
class EmptyQuerySetTests(TestCase):
|
1700 | 1700 | |
1701 | 1701 | |
1702 | 1702 | class ValuesQuerysetTests(BaseQuerysetTest): |
1703 | | def test_flat_values_lits(self): |
| 1703 | def setUp(self): |
1704 | 1704 | Number.objects.create(num=72) |
| 1705 | |
| 1706 | def test_flat_values_lits(self): |
1705 | 1707 | qs = Number.objects.values_list("num") |
1706 | 1708 | qs = qs.values_list("num", flat=True) |
1707 | 1709 | self.assertValueQuerysetEqual( |
1708 | 1710 | qs, [72] |
1709 | 1711 | ) |
1710 | 1712 | |
| 1713 | def test_extra_values(self): |
| 1714 | qs = Number.objects.extra(select={'value_plus_one': 'num+1'}).order_by('value_plus_one') |
| 1715 | qs = qs.values('num') |
| 1716 | identity = lambda x:x |
| 1717 | self.assertQuerysetEqual(qs, [{'num': 72}], identity) |
| 1718 | |
| 1719 | def test_extra_values_list(self): |
| 1720 | qs = Number.objects.extra(select={'value_plus_one': 'num+1'}).order_by('value_plus_one') |
| 1721 | qs = qs.values_list('num') |
| 1722 | identity = lambda x:x |
| 1723 | self.assertQuerysetEqual(qs, [(72,)], identity) |
| 1724 | |
1711 | 1725 | |
1712 | 1726 | class WeirdQuerysetSlicingTests(BaseQuerysetTest): |
1713 | 1727 | def setUp(self): |