Opened 14 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 , 14 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 14 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 , 14 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
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 , 14 years ago
Component: | Database layer (models, ORM) → Documentation |
---|---|
Triage Stage: | Unreviewed → Accepted |
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 , 14 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 , 14 years ago
Type: | → Bug |
---|
comment:7 by , 14 years ago
Severity: | → Normal |
---|
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.