Opened 8 years ago

Closed 8 years ago

#8144 closed (wontfix)

values_list doesn't give the full object when requested

Reported by: Kenneth Arnold Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords: values_list
Cc: kenneth.arnold@… Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

values_list is very useful to us, but one thing that keeps it from being more useful is that it will not return full objects when we ask for them.

Current behavior:

Model.objects.values_list('other') # yields ids

Desired behavior:

Model.objects.values_list('other_id') # yields ids
Model.objects.values_list('other')    # yields objects

This of course requires getting extra things from the database, akin to select_related. We prefer values_list because it is more explicit and doesn't require pulling in all the fields of the first model (Model, above) where we don't ask for them.

Change History (2)

comment:1 Changed 8 years ago by Jeff Anderson

Triage Stage: UnreviewedDesign decision needed

comment:2 Changed 8 years ago by Malcolm Tredinnick

Resolution: wontfix
Status: newclosed

This would be a backwards-incompatible change and not necessarily desirable behaviour for everybody. Also, values_list() is just another presentation for of values(), so should always mirror that (and changing values() behaviour would affect a lot of people). The solution here is to write your own QuerySet subclass that does the conversion you're after.

One day, maybe, if there's a really good API, we might support this in core, but, really, values() and values_list() return raw values intentionally. If you want Python objects, just use a normal QuerySet.

Note: See TracTickets for help on using tickets.
Back to Top