#29442: wrong sql for cast datetime to date in sqlite backend
-------------------------------------+-------------------------------------
               Reporter:  Mauro      |          Owner:  nobody
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  1.11
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:  sqlite3 cast
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 "data_dimissione" is datetime field and I need list of days, so my
 queryset is like

 qs = objects.all().annotate(date_only=Cast("data_dimissione",
 DateField())).values_list('date_only', flat=True).distinct()

 It works on mysql , but django 1.11.10-1~bpo9+1 with sqlite3
 3.16.2-5+deb9u1  raise TypeError
 {{{
   .....
   File  "../site-packages/django/db/backends/sqlite3/operations.py", line
 232, in convert_datefield_value
     raise e
 TypeError: expected string or buffer
 }}}

 Reason is  sql query is  like

 SELECT DISTINCT CAST("ps_ps"."data_dimissione" AS date) AS "date_only",
 ........

 but data results is
 2018|......
 see https://code.djangoproject.com/ticket/28727#comment:6


 Correct sql seems
 SELECT DISTINCT date("ps_ps"."data_dimissione" ) AS "date_only", .

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29442>
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/050.7aa495a00d3982365625942d83b45776%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to