#10929: Support a default value for Sum (and possibly other aggregation 
functions)
-------------------------------------+-------------------------------------
     Reporter:  nolan                |                    Owner:
         Type:  New feature          |                   Status:  new
    Component:  ORM aggregation      |                  Version:  SVN
     Severity:  Normal               |               Resolution:
     Keywords:  aggregate annotate   |             Triage Stage:  Accepted
  default                            |      Needs documentation:  1
    Has patch:  1                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------

Comment (by lukeplant):

 There is a good case for giving `Sum` a default of zero, while leaving
 `Max` and `Min` with default of `None`. Essentially, the reason is that
 zero is the fixed point of the `+` operator, while max and min have no
 fixed points (excluding negative infinity and positive infinity
 respectively, which are problematic). Also, it makes the behaviour
 analogous to the Python builtins `sum`, `min` and `max` - `sum` returns 0
 for an empty list, whereas `min` and `max` throw exceptions. (We don't
 want to throw exceptions here, for various obvious reasons, but I think we
 should be indicating 'undefined' in ''some'' way under the same
 circumstances).

 If we do this, we need a note in the release notes about the backwards
 incompatibility - if people were relying on Sum returning None for no data
 instead of zero. (We can certainly classify the previous behaviour as a
 bug, since it was out of line with our docs, and neither expected or
 useful behaviour, but should still mention this).  We should also have
 some tests that ensure that it returns a zero of the right type for
 different underlying field types.

 This also brings up the possibility of whether the default for `Sum`
 should act like the `start` parameter of the `sum` Python builtin. I think
 it should. That would make implementation harder, though, I guess.
 Alternatively we could have a separate 'start' parameter for `Sum`, which
 might be clearer, and would make that a separate feature.

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to