Opened 9 years ago

Closed 8 years ago

#7256 closed (fixed)

extra() does not play well with values()

Reported by: Nicolas Lara Owned by: Nicolas Lara
Component: Database layer (models, ORM) Version: master
Severity: Keywords: qsrf-cleanup extra values
Cc: jdunck@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When using extra() on a ValuesQuerySet or aplying values to a queryset with extra_select, the selection done by extra() is not preserved

>>> Book.objects.all().values().extra(select={'price_per_page' : 'price / pages'}).get(pk=1)
{'id': 1,
 'isbn': u'159059725',
 'name': u' The Definitive Guide to Django: Web Development Done Right',
 'pages': 447,
 'price': 30.0,
 'publisher_id': 1}

>>> Book.objects.all().extra(select={'price_per_page' : 'price / pages'}).values().get(pk=1)
{'id': 1,
 'isbn': u'159059725',
 'name': u' The Definitive Guide to Django: Web Development Done Right',
 'pages': 447,
 'price': 30.0,
 'publisher_id': 1}

while:

>>> Book.objects.all().extra(select={'price_per_page' : 'price / pages'}).get(pk=1).__dict__
{'id': 1,
 'isbn': u'159059725',
 'name': u' The Definitive Guide to Django: Web Development Done Right',
 'pages': 447,
 'price': 30.0,
 'price_per_page': 0.067114093959731502,
 'publisher_id': 1}

I am assigning the ticket to myself, but wont work on it until after aggregation is stable (also im waiting for it to be 'Accepted').

Attachments (1)

extra_values.diff (1.3 KB) - added by Nicolas Lara 8 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 9 years ago by George Vilches

Keywords: qsrf-cleanup added

Marking as qsrf-cleanup since it seems to be a problem introduced with the QSRF changes. Just getting more eyes on DB-related stuff.

comment:2 Changed 8 years ago by Nicolas Lara

Has patch: set

I was about to un-claim the ticket but decided to check the code a bit before doing it. Turns out it was a really simple fix.

Changed 8 years ago by Nicolas Lara

Attachment: extra_values.diff added

comment:3 Changed 8 years ago by anonymous

Cc: jdunck@… added

comment:4 Changed 8 years ago by edgarsj

Triage Stage: UnreviewedAccepted

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

Resolution: fixed
Status: newclosed

(In [7636]) Fixed #7256 -- Corrected queryset code to return the correct set of columns when the query has an empty values() clause as well as extra selects from an extra() clause. Thanks to Nicolas Lara for the report and patch.

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