diff options
| author | Simon Charette <charettes@users.noreply.github.com> | 2018-02-08 09:59:25 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-02-08 10:00:12 -0500 |
| commit | 8d03356d35a91e2a8536bae4319f061ccf6c0294 (patch) | |
| tree | 349265e3049e53dcbd98b379761ab95d765f620a /django | |
| parent | 781a3372421da6d44f7cc60d3c539ada2537582b (diff) | |
[2.0.x] Fixed #29108 -- Fixed crash in aggregation of distinct+ordered+sliced querysets.
Regression in 4acae21846f6212aa992763e587c7e201828d7b0.
Thanks Stephen Brooks for the report.
Backport of d61fe246015aa4fdc6dcb837ffb1442fa71ae586 from master
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/sql/compiler.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 839e37aa8a..72a6537e05 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -559,7 +559,9 @@ class SQLCompiler: # to exclude extraneous selects. sub_selects = [] sub_params = [] - for select, _, alias in self.select: + for index, (select, _, alias) in enumerate(self.select, start=1): + if not alias and with_col_aliases: + alias = 'col%d' % index if alias: sub_selects.append("%s.%s" % ( self.connection.ops.quote_name('subquery'), @@ -573,7 +575,7 @@ class SQLCompiler: return 'SELECT %s FROM (%s) subquery' % ( ', '.join(sub_selects), ' '.join(result), - ), sub_params + params + ), tuple(sub_params + params) return ' '.join(result), tuple(params) finally: |
