[Django] #26458: The Avg aggregate should only automatically resolves its output field to FloatField on numeric sources

5 views
Skip to first unread message

Django

unread,
Apr 4, 2016, 12:44:40 PM4/4/16
to django-...@googlegroups.com
#26458: The Avg aggregate should only automatically resolves its output field to
FloatField on numeric sources
-------------------------------------+-------------------------------------
Reporter: charettes | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database | Version: master
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Before #24649 was fixed it was simply not possible to use the `Avg`
function on non-numeric sources. The *good enough* solution was to allow
use of the `output_field` kwarg and document it should be used when
averaging `DurationField`.

As `DurationField` uses different underlying datatype for its storage
(bigint, interval, ...) averaging on such fields
[https://groups.google.com/d/msg/django-users/BwkK7R1WXYU/k4b5nzNwAQAJ
might require or not] an explicit `output_field` and can be a source of
confusion.

As the SQL `AVG` function only defaults to using floating value datatype
as a return value when numeric input is used I suggest adjusting the `Avg`
expression's `output_field` resolution to only use `FloatField` for
default when its source field is an instance of one of Django's numerical
field classes. This would lift the requirement of explicitly specifying an
`output_field` when averaging `DurationField` on PostgreSQL.

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

Django

unread,
Apr 4, 2016, 12:56:46 PM4/4/16
to django-...@googlegroups.com
#26458: The Avg aggregate should only automatically resolves its output field to
FloatField on numeric sources
-------------------------------------+-------------------------------------
Reporter: charettes | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


Comment:

https://github.com/django/django/pull/6413

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

Django

unread,
Apr 4, 2016, 6:46:14 PM4/4/16
to django-...@googlegroups.com
#26458: The Avg aggregate should only automatically resolves its output field to
FloatField on numeric sources
-------------------------------------+-------------------------------------
Reporter: charettes | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* stage: Unreviewed => Accepted


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

Django

unread,
Apr 5, 2016, 11:46:39 AM4/5/16
to django-...@googlegroups.com
#26458: The Avg aggregate should only automatically resolves its output field to
FloatField on numeric sources
-------------------------------------+-------------------------------------
Reporter: charettes | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

* stage: Accepted => Ready for checkin


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

Django

unread,
Apr 5, 2016, 11:48:27 PM4/5/16
to django-...@googlegroups.com
#26458: The Avg aggregate should only automatically resolves its output field to
FloatField on numeric sources
-------------------------------------+-------------------------------------
Reporter: charettes | Owner: nobody
Type: | Status: closed

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

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette <charettes@…>):

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


Comment:

In [changeset:"a6074e8908e36286de7e31f165be801df8ee1eab" a6074e89]:
{{{
#!CommitTicketReference repository=""
revision="a6074e8908e36286de7e31f165be801df8ee1eab"
Fixed #26458 -- Based Avg's default output_field resolution on its source
field type.

Thanks Tim for the review and Josh for the input.
}}}

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

Reply all
Reply to author
Forward
0 new messages