#27980: ExpressionWrapper is maybe masking a NotImplementedError on SQLite
-------------------------------------+-------------------------------------
               Reporter:             |          Owner:  nobody
  denisroldan                        |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  1.10
  layer (models, ORM)                |       Keywords:  db, orm, sqlite,
               Severity:  Normal     |  datetime, NotImplementedError
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 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.

--
Ticket URL: <https://code.djangoproject.com/ticket/27980>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/054.4fcbb8874cfd3054fec02f87c4fe4ee8%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to