#17796 closed Bug (fixed)
Aggregating an IntegerField returns Decimal from MySQL
Reported by: | adsva | Owned by: | nobody |
---|---|---|---|
Component: | Uncategorized | Version: | dev |
Severity: | Normal | Keywords: | orm, aggregate |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
>>> MyModel.objects.get(pk=1).my_int_field >>> 581L >>> MyModel.objects.filter(pk=1).aggregate(Sum('my_int_field')) >>> {'my_int_field__sum': Decimal('581')}
The aggregate used to return an integer until recently.
It looks like changeset:17588 added a convert_values-method to the DataBaseOperations class for the MySQL backend, but since it only handles Boolean conversions, it should probably call the parent's convert_values if it's not a boolean?
Attachments (1)
Change History (3)
by , 13 years ago
Attachment: | aggtype.patch added |
---|
comment:1 by , 13 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:2 by , 13 years ago
Replying to adsva:
It looks like changeset:17588 added a convert_values-method to the DataBaseOperations class for the MySQL backend, but since it only handles Boolean conversions, it should probably call the parent's convert_values if it's not a boolean?
Yes I had seen the test failures that started to show with that commit under Python 2.5 and 2.6 against MySQL and had been able to reproduce them with Python 2.6 (original work and testing on the fix for #15169 had been done only with 2.7).
I tried to fix these problems following the same strategy you suggest (falling back the parent method) but it introduces its own problems, in particular the fallback to return float(value)
causes an inmediate error when processing CHAR-based fields as can be seen when trying to run the test suite. This seems to indicate convert_values()
is currently being called from some but not all of the code paths in which data flows from the DB to the model layer, at least in the MySQL case.
I decided to simply undo the change until this problem can be analized with more time and without the risk of breaking things at this point of the 1.4 release cycle.
In [17603]: