#28328: QuerySet.only doesn't work with QuerySet.difference
-------------------------------------+-------------------------------------
Reporter: Dmitry | Owner: nobody
Dygalo |
Type: | Status: new
Uncategorized |
Component: Database | Version: 1.11
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
**models.py**:
{{{
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.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/055.251747d472eaa1261f2de0de484a969a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.