diff options
| author | Ran Benita <ran234@gmail.com> | 2017-12-23 11:35:08 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-12-26 12:18:39 -0500 |
| commit | 4e4619a2b8f79699fbdb2c4f1bc4db55f59af6e6 (patch) | |
| tree | 58c72a678e7247df8d293310d509e26a4cc8d5a9 /django/db/models/sql | |
| parent | 830636df739d359116e3106c35375ac838bf15c3 (diff) | |
[2.0.x] Fixed #28944 -- Fixed crash when chaining values()/values_list() after QuerySet.select_for_update(of=()).
Backport of c21f158295d92e35caf96436bfdbbff554fc5569 from master
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/compiler.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 279aa7a00f..839e37aa8a 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -190,7 +190,7 @@ class SQLCompiler: "AS alias" for the column (possibly None). The klass_info structure contains the following information: - - Which model to instantiate + - The base model of the query. - Which columns for that model are present in the query (by position of the select clause). - related_klass_infos: [f, klass_info] to descent into @@ -207,20 +207,21 @@ class SQLCompiler: select_idx += 1 assert not (self.query.select and self.query.default_cols) if self.query.default_cols: + cols = self.get_default_columns() + else: + # self.query.select is a special case. These columns never go to + # any model. + cols = self.query.select + if cols: select_list = [] - for c in self.get_default_columns(): + for col in cols: select_list.append(select_idx) - select.append((c, None)) + select.append((col, None)) select_idx += 1 klass_info = { 'model': self.query.model, 'select_fields': select_list, } - # self.query.select is a special case. These columns never go to - # any model. - for col in self.query.select: - select.append((col, None)) - select_idx += 1 for alias, annotation in self.query.annotation_select.items(): annotations[alias] = select_idx select.append((annotation, alias)) |
