#27535: RFE: Exclude pk from queries
-------------------------------------+-------------------------------------
Reporter: Alexander | Owner: nobody
Todorov |
Type: New | Status: new
feature |
Component: Database | Version: 1.10
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 |
-------------------------------------+-------------------------------------
Hello guys,
in `models/sql/query.py` there is this snippet:
{{{
def deferred_to_data(self, target, callback):
... skip ...
must_include = {orig_opts.concrete_model: {orig_opts.pk}}
}}}
introduced in
https://github.com/django/django/commit/29050ef999e1931efb6c62471c7e07d2ea5e96ea,
which is causing the following difference between queries:
{{{
>>> print(Book.objects.values('genre').query)
SELECT "demoproject_book"."genre_id" FROM "demoproject_book"
>>>
}}}
is different from
{{{
>>> print(Book.objects.only('genre').query)
SELECT "demoproject_book"."id", "demoproject_book"."genre_id" FROM
"demoproject_book"
}}}
Because the "id" field is included in the second query it produces
different values when .annotate()-ed.
In the environment I work with I don't want to use .values() b/c when I
iterate over the results I need to have the objects, not a dict of values.
I'm requesting a method for excluding the PK field from the query.
Alternatively I'd like for the .values() method to have an alternative
which returns model objects, not dictionary.
Can you point me in the right direction? I'm willing to provide a patch.
--
Ticket URL: <https://code.djangoproject.com/ticket/27535>
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/051.f4292ec31b95a0031ffe0d7e316f309f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.