Opened 17 years ago

Closed 17 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: dev
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: no UI/UX: no

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 17 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 by George Vilches, 17 years ago

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 by Nicolas Lara, 17 years ago

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.

by Nicolas Lara, 17 years ago

Attachment: extra_values.diff added

comment:3 by anonymous, 17 years ago

Cc: jdunck@… added

comment:4 by edgarsj, 17 years ago

Triage Stage: UnreviewedAccepted

comment:5 by Russell Keith-Magee, 17 years ago

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