[Django] #25871: Allow expressions in values() queryset method

35 views
Skip to first unread message

Django

unread,
Dec 5, 2015, 9:10:45 PM12/5/15
to django-...@googlegroups.com
#25871: Allow expressions in values() queryset method
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner: nobody
Type: New | Status: new
feature |
Component: Database | Version: master
layer (models, ORM) |
Severity: Normal | Keywords: expressions
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
It should be possible to insert expressions directly into a `values()`
method, rather than first annotating and then selecting in values().

{{{
# Proposed
Model.objects.values(complex=SomeExpression()).aggregate(Sum('field'))

# Current
Model.objects.annotate(complex=SomeExpression()).values('complex').aggregate(Sum('field'))
}}}

The major hurdle here is allowing `**kwargs` into `values()` to support
the alias. That's an addition to the API so should be backwards
compatible, but it'll also probably rule out using various state based
kwargs like `flat=True` and their ilk in the future. We could do some
juggling to ensure we're only processing expression kwargs as expressions
by checking if they have the attribute `resolve_expression`.

--
Ticket URL: <https://code.djangoproject.com/ticket/25871>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 7, 2015, 8:30:02 PM12/7/15
to django-...@googlegroups.com
#25871: Allow expressions in values() queryset method
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: expressions | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* stage: Unreviewed => Accepted


Comment:

Related to "`QuerySet.values()` should be aliasable (#16735)" and
[https://groups.google.com/d/topic/django-
developers/m4lPPfFChNY/discussion django-developers discussion].

--
Ticket URL: <https://code.djangoproject.com/ticket/25871#comment:1>

Django

unread,
Aug 14, 2016, 7:47:23 PM8/14/16
to django-...@googlegroups.com
#25871: Allow expressions in values() queryset method
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner: Ian-Foote
Type: New feature | Status: assigned

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: expressions | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ian-Foote):

* owner: nobody => Ian-Foote
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/25871#comment:2>

Django

unread,
Aug 14, 2016, 9:53:57 PM8/14/16
to django-...@googlegroups.com
#25871: Allow expressions in values() queryset method
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner: Ian-Foote
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: expressions | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ian-Foote):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/25871#comment:3>

Django

unread,
Aug 18, 2016, 4:07:35 PM8/18/16
to django-...@googlegroups.com
#25871: Allow expressions in values() queryset method
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner: Ian-Foote
Type: New feature | Status: closed

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: expressions | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"39f35d4b9de223b72c67bb1d12e65669b4e1355b" 39f35d4b]:
{{{
#!CommitTicketReference repository=""
revision="39f35d4b9de223b72c67bb1d12e65669b4e1355b"
Fixed #25871 -- Added expressions support to QuerySet.values().
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25871#comment:4>

Reply all
Reply to author
Forward
0 new messages