Value conversions of aggregate return values -- is float conversion really required?

151 views
Skip to first unread message

Tommi Penttinen

unread,
Feb 15, 2010, 4:40:12 PM2/15/10
to django-d...@googlegroups.com
Hi,

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-

Russell Keith-Magee

unread,
Feb 16, 2010, 7:01:20 AM2/16/10
to django-d...@googlegroups.com

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 %-)

Reply all
Reply to author
Forward
0 new messages