#24662: Sum() returns True/False when used with BooleanField & MySQL
-------------------------------------+-------------------------------------
     Reporter:  chriskief            |                    Owner:  marco-
                                     |  santamaria
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  1.8
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by jarshwah):

 * cc: josh.smeaton@… (added)


Comment:

 I'm not sure what the correct behaviour should be, but I don't think True
 is correct. I'm surprised the previous behaviour returned a Decimal -
 that's about the most unlikely type I would think to be returned.

 SUM(bool) only works on databases that use numbers to represent booleans
 (1, 0). You can get exactly the same behaviour by doing COUNT(bool) and
 that will be properly supported. You could also try
 `.aggregate(Sum('bool_field', output_type=IntegerField()))` if you really
 wanted to keep that behaviour.

 I'm tempted to close this as wontfix, because SUM(bool) only ever worked
 by accident, and as a by-product of internal representation of some
 backends. The correct way to calculate the result is by using count. Can
 you convince me that this behaviour should be supported?

--
Ticket URL: <https://code.djangoproject.com/ticket/24662#comment:4>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.497e03a19748fd77f568997fadef03fa%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to