Opened 8 years ago

Closed 7 years ago

#15546 closed Bug (fixed)

Fields selected via extra() are omitted in ValuesQuerySet when fields are specified

Reported by: Jannis Owned by: nobody
Component: Documentation Version: 1.3-beta
Severity: Normal Keywords: extra valuesqueryset
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Books.objects.values().extra(select={'price_per_page': 'price / page'}) works fine.

Books.objects.values('book_id').extra(select={'price_per_page': 'price / page'}) however, does not.

Change History (8)

comment:1 Changed 8 years ago by Russell Keith-Magee

Resolution: invalid
Status: newclosed

Working as designed. You've explicitly specified the values you want to be returned; if you want the extra column to be returned, you need to include it in the values() clause.

comment:2 Changed 8 years ago by Jannis

Correct me if I'm wrong but don't the docs say the opposite?

If you use a values() clause after an extra() clause, any fields defined by a select argument in the extra() must be explicitly included in the values() clause. However, if the extra() clause is used after the values(), the fields added by the select will be included automatically.

comment:3 Changed 8 years ago by Russell Keith-Magee

Resolution: invalid
Status: closedreopened

Hrm. This requires further investigation. I was fairly certain that values + extra was fairly extensively tested (see the extra_regress regression tests), so either the documentation is incorrect, or the tests are incomplete or incorrect.

comment:4 Changed 8 years ago by Russell Keith-Magee

Component: Database layer (models, ORM)Documentation
Triage Stage: UnreviewedAccepted

Ok - this looks like a failure of documentation. The current behavior has been tested since at least the 1.0 branch, so the documentation hasn't reflected reality for some time.

comment:5 Changed 8 years ago by Jannis

Maybe I should be asking this on the django-developers list but what is the rationale behind ignoring the extra-fields after a values() clause?

As values() has a grouping function when used in aggregation, it would be quite handy if additional fields could be added with extra().

comment:6 Changed 8 years ago by Luke Plant

Type: Bug

comment:7 Changed 8 years ago by Luke Plant

Severity: Normal

comment:8 Changed 7 years ago by Malcolm Tredinnick

Resolution: fixed
Status: reopenedclosed

In [16697]:

Corrected explanation of values() and extra() interaction in querysets.

Fixes #15546, refs #13455. The original documentation patch
inadvertently muddied the waters in one aspect and this commit tidies
that up.

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