﻿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
27491	TruncDay function arguments aren't quoted properly when you print the SQL query	Nick Retallack	nobody	"Here's how I discovered it.

Create a model:

{{{
class Thing(models.Model):
    timestamp = models.DateTimeField(auto_now_add=True)
}}}

Now lets query it:

{{{
$ ./manage.py shell
>>> from django.db.models.functions import TruncDay
>>> from stuff.models import Thing
>>> print Thing.objects.annotate(truncstamp=TruncDay('timestamp')).values('truncstamp').query
SELECT CAST(DATE_FORMAT(CONVERT_TZ(`stuff_thing`.`timestamp`, 'UTC', UTC), '%Y-%m-%d 00:00:00') AS DATETIME) AS `truncstamp` FROM `stuff_thing`
}}}

Look at this query.  UTC isn't quoted!  If you try to paste this into your MySQL console, that quoting is not going to work.  That parameter remains unquoted no matter what you set your TIME_ZONE to.
"	Uncategorized	closed	Database layer (models, ORM)	1.10	Normal	invalid			Unreviewed	0	0	0	0	0	0
