Code

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#17796 closed Bug (fixed)

Aggregating an IntegerField returns Decimal from MySQL

Reported by: adsva Owned by: nobody
Component: Uncategorized Version: master
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)

aggtype.patch (649 bytes) - added by adsva 2 years ago.

Download all attachments as: .zip

Change History (3)

Changed 2 years ago by adsva

comment:1 Changed 2 years ago by ramiro

  • Resolution set to fixed
  • Status changed from new to closed

In [17603]:

Fixed #17796 -- Rolled back [17588] because the fix for the original relatively
corner case (boolean fields under MySQL spatial backend) had a wider scope with
potentially unintended consequences affecting the main MySQL backend and the
required changes wouldn't be appropiate at this point of the 1.4 development
cycle.

Refs #15169.

comment:2 in reply to: ↑ description Changed 2 years ago by ramiro

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.