Django

Code

Ticket #7256 (closed: fixed)

Opened 7 months ago

Last modified 6 months ago

extra() does not play well with values()

Reported by: nicolas Assigned to: nicolas
Milestone: Component: Database layer (models, ORM)
Version: SVN Keywords: qsrf-cleanup extra values
Cc: jdunck@gmail.com Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

extra_values.diff (1.3 kB) - added by nicolas on 06/11/08 14:33:08.

Change History

06/10/08 09:56:16 changed by gav

  • keywords changed from extra values to qsrf-cleanup extra values.
  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

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

06/11/08 14:32:49 changed by nicolas

  • has_patch set to 1.

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.

06/11/08 14:33:08 changed by nicolas

  • attachment extra_values.diff added.

06/11/08 15:46:50 changed by anonymous

  • cc set to jdunck@gmail.com.

06/11/08 16:26:20 changed by edgarsj

  • stage changed from Unreviewed to Accepted.

06/15/08 01:24:42 changed by russellm

  • status changed from new to closed.
  • resolution set to fixed.

(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.


Add/Change #7256 (extra() does not play well with values())




Change Properties
Action