#28727: sqlite: CAST to DATE causes error
-------------------------------------+-------------------------------------
               Reporter:  direx      |          Owner:  nobody
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  1.11
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 When trying to cast a date object to a `DateField` in `annotate` an
 exception is raised:

 {{{
 import datetime
 from django.contrib.auth.models import User
 from django.db import models
 from django.db.models.functions import Cast

 User.objects.all().annotate(today=Cast(datetime.date.today(),
 models.DateField()))

 ...

 TypeError: expected string or buffer
 }}}

 This only seems to happen with SQLite, MySQL works as expected.

 FYI, this is the SQL which is generated for SQLite:

 {{{
 SELECT "auth_user"."id", "auth_user"."password", "auth_user"."last_login",
 "auth_user"."is_superuser", "auth_user"."username",
 "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email",
 "auth_user"."is_staff", "auth_user"."is_active",
 "auth_user"."date_joined", CAST(2017-10-20 AS date) AS "today" FROM
 "auth_user"
 }}}

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

Reply via email to