tickets: 24662
This data as json
id | created | changetime | last_pulled_from_trac | stage | status | component | type | severity | version | resolution | summary | description | owner | reporter | keywords | easy | has_patch | needs_better_patch | needs_tests | needs_docs | ui_ux |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
24662 | 2015-04-19 01:48:47 | 2015-04-20 06:40:49 | 2022-03-06 04:28:53.932664 | Accepted | assigned | Database layer (models, ORM) | Bug | Normal | 1.8 | Sum() returns True/False when used with BooleanField & MySQL | 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} }}} | marco-santamaria | chriskief | 0 | 0 | 0 | 0 | 0 | 0 |