#27491: TruncDay function arguments aren't quoted properly when you print the 
SQL
query
-------------------------------------+-------------------------------------
               Reporter:  Nick       |          Owner:  nobody
  Retallack                          |
                   Type:             |         Status:  new
  Uncategorized                      |
              Component:  Database   |        Version:  1.10
  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          |
-------------------------------------+-------------------------------------
 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.

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

Reply via email to