{{{
class Model(models.Model):
description = models.CharField(max_length=255)
}}}
**Actual behavior**:
{{{
>>> to_remove = Model.objects.filter(description='TO_REMOVE')
>>> query_set = Model.objects.all().difference(to_remove).only('pk')
>>> print(query_set.query)
(SELECT "test_model"."id", "test_model"."description" FROM "test_model")
EXCEPT (SELECT "test_model"."id", "test_model"."description" FROM
"test_model" WHERE "test_model"."description" = TO_REMOVE)
}}}
**Expected**:
{{{
>>> to_remove = Model.objects.filter(description='TO_REMOVE')
>>> query_set = Model.objects.all().difference(to_remove).only('pk')
>>> print(query_set.query)
(SELECT "test_model"."id" FROM "test_model") EXCEPT (SELECT
"test_model"."id", "test_model"."description" FROM "test_model" WHERE
"test_model"."description" = TO_REMOVE)
}}}
**The problem**:
Even if I use `.only('pk')` there is still "description" column in SELECT
in the query, but I expect only "id" field as was specified in `only`.
--
Ticket URL: <https://code.djangoproject.com/ticket/28328>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* type: Uncategorized => Bug
* resolution: => invalid
Comment:
I believe it's unsupported but doesn't raise an error yet. As
[https://docs.djangoproject.com/en/dev/ref/models/querysets/#union per the
documentation], "only LIMIT, OFFSET, and ORDER BY (i.e. slicing and
order_by()) are allowed on the resulting QuerySet." See #27995 for a
ticket to raise a helpful message about this.
--
Ticket URL: <https://code.djangoproject.com/ticket/28328#comment:1>