diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2017-11-12 14:28:11 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2017-11-12 14:31:21 +0100 |
| commit | ca0a9c938f3c0f165fe1e6d805c2d5d0541236aa (patch) | |
| tree | 05d715bfbb218923089307b2cc50f9338aed5b37 /django/db/models/sql | |
| parent | 3c8c3ff637e2c0c325e5638d2c56ae1938f0885d (diff) | |
[2.0.x] Fixed #28781 -- Added QuerySet.values()/values_list() support for union(), difference(), and intersection().
Thanks Tim Graham for the review.
Backport of 2d3cc94284674638c334670903d49565039d77ae from master
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/compiler.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 7199dd4b09..2b08b9d79e 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -407,6 +407,11 @@ class SQLCompiler: parts = () for compiler in compilers: try: + # If the columns list is limited, then all combined queries + # must have the same columns list. Set the selects defined on + # the query on all combined queries, if not already set. + if not compiler.query.values_select and self.query.values_select: + compiler.query.set_values(self.query.values_select) parts += (compiler.as_sql(),) except EmptyResultSet: # Omit the empty queryset with UNION and with DIFFERENCE if the |
