﻿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
27980	ExpressionWrapper is maybe masking a NotImplementedError on SQLite	Denis Roldán	nobody	"Hello folks!

The new ExpressionWrapper is maybe masking some NotImplementedErrors. Here's an example:

Under Django 1.10 & Python 3.6:

If I try 

{{{
tasks = Task.objects.all()
tasks.annotate(time_elapsed=Sum(F('resolution_date')-F('request_date'), output_field=DateTimeField())).aggregate(Avg('time_elapsed'))
}}}

Falls correctly into:

{{{
NotImplementedError: You cannot use Sum, Avg, StdDev, and Variance aggregations on date/time fields in sqlite3 since date/time is saved as text.
}}}

Of course, if I change into Postgre all runs smoothly. Unfortunately if I use the brand new ExpressionWrapper I don't get any exception raised:

{{{
from django.db.models import ExpressionWrapper, F, DurationField, Avg

tasks = Task.objects.all()
duration = ExpressionWrapper(F('resolution_date') - F('request_date'), output_field=DurationField())
tasks.annotate(time_elapsed=duration).aggregate(Avg('time_elapsed'))
{'time_elapsed__avg': None}

}}}

Under postgre and MySQL I can get that value and, of course, is not None. And, by the way, you can do this:

{{{
tasks.annotate(time_elapsed=duration)[0].time_elapsed
datetime.timedelta(16, 74471, 878000)
}}}

So maybe it's a bug of the Avg Implementation when using a ExpressionWrapper or maybe the exception is masked as None."	Bug	closed	Database layer (models, ORM)	1.10	Normal	invalid	db, orm, sqlite, datetime, NotImplementedError		Unreviewed	0	0	0	0	0	0
