Opened 7 years ago

Closed 7 years ago

#7256 closed (fixed)

extra() does not play well with values()

Reported by: nicolas Owned by: nicolas
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 7 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 7 years ago by gav

  • Keywords qsrf-cleanup added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 7 years ago by nicolas

  • 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 7 years ago by nicolas

comment:3 Changed 7 years ago by anonymous

  • Cc jdunck@… added

comment:4 Changed 7 years ago by edgarsj

  • Triage Stage changed from Unreviewed to Accepted

comment:5 Changed 7 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(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