﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
24649	Allow using the Avg aggregate on non-numeric field types	Manuel Dominguez	nobody	"I am using the new DurationField and I tried to query the average value of that field but instead of returning any value the code raises a TypeError. The problem is that the Avg aggregate function tries to cast the returned value to float.

{{{
    def convert_value(self, value, expression, connection, context):
        if value is None:
            return value
        return float(value)
}}}

As the returned value is a timedelta the casting fails. I do not know if the right way to solve this is to allow to return timedeltas or use a new aggregate function just for DurationFields but I have solved with the latest.


{{{
class AvgDuration(Avg):
    def convert_value(self, value, expression, connection, context):
        return value
}}}
"	New feature	closed	Database layer (models, ORM)	dev	Normal	fixed		josh.smeaton@…	Accepted	1	0	0	0	0	0
