I thought I'd check with you before creating a ticket.
Django's aggregate documentation http://docs.djangoproject.com/en/dev/ref/models/querysets/#id8
states that return type for aggregates Max, Min and Sum is the same
as the input field.
However, currently values for all fields with internal types other
than DecimalField, *IntegerField, AutoField, DateField, DateTimeField,
TimeField are converted into floats (in
DataBaseOperations.convert_values in django/db/backends/__init__.py).
This conflicts both the documentation (which of course could be out of
sync) and makes developing additional aggregates (e.g. on strings) a
real pain.
Thus, is there a real reason for that conversion?
If not, I'll create a ticket and submit the little patch.
-Tommi Penttinen-
There's no specific reason. As the inline comment notes, "float" is
just a reasonable fallback value for the set of aggregates that ship
with Django.
Of course, it isn't very reasonable if you're dealing with strings :-)
Ironically, the SQLite backend behaves a little better in this regard
-- it doesn't coerce on the fallthrough case.
Patches are certainly welcome. One quick word of warning -- I have a
vague recollection that there was a edge case that required the
slightly overenthusiastic type conversion, so make sure your patch
still passes the aggregate and aggregate_regress tests.
Yours,
Russ Magee %-)