Opened 13 years ago

Closed 13 years ago

#15546 closed Bug (fixed)

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

Reported by: Jannis Vajen 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

Description

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 by Russell Keith-Magee, 13 years ago

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 by Jannis Vajen, 13 years ago

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.

http://docs.djangoproject.com/en/dev/ref/models/querysets/#values

comment:3 by Russell Keith-Magee, 13 years ago

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 by Russell Keith-Magee, 13 years ago

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 by Jannis Vajen, 13 years ago

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 by Luke Plant, 13 years ago

Type: Bug

comment:7 by Luke Plant, 13 years ago

Severity: Normal

comment:8 by Malcolm Tredinnick, 13 years ago

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