id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux 24662 Sum() returns True/False when used with BooleanField & MySQL Chris Kief Marco Santamaria "When using Sum() on a BooleanField when only 1 record is present, the ORM returns True/False rather than 1/0. I've tested with MySQL and SQLite, only MySQL exhibits the bug. This is a change in behavior from previous versions of Django where a Decimal would be returned. Environment: MySQL - 5.6.24 MySQL-python==1.2.5 Code to reproduce (new project / app): {{{ class Example(models.Model): foo = models.BooleanField(default=True) }}} Simple query to demonstrate the difference: {{{ # add a single row a = Example() a.save() # query Example.objects.all().aggregate(count=Count('foo'), sum=Sum('foo')) # results # notice Django 1.8 + MySQL Django 1.7.7 + MySQL {'count': 1, 'sum': Decimal('1')} Django 1.7.7 + SQLite {'count': 1, 'sum': 1} Django 1.8 + MySQL {'count': 1, 'sum': True} Django 1.8 + SQLite {'count': 1, 'sum': 1} # add a second row a = Example() a.save() # query Example.objects.all().aggregate(count=Count('foo'), sum=Sum('foo')) # results # notice Django 1.8 + MySQL now returns a decimal Django 1.7.7 + MySQL {'count': 2, 'sum': Decimal('2')} Django 1.7.7 + SQLite {'count': 2, 'sum': 2} Django 1.8 + MySQL {'count': 2, 'sum': Decimal('2')} Django 1.8 + SQLite {'count': 2, 'sum': 2} }}}" Bug closed Database layer (models, ORM) 1.8 Normal wontfix josh.smeaton@… Accepted 0 0 0 0 0 0