﻿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
28727	sqlite: CAST to DATE causes error	direx	nobody	"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""
}}}
"	Bug	new	Database layer (models, ORM)	1.11	Normal				Unreviewed	0	0	0	0	0	0
