#23524: Django postgres connection's timezone is always set to UTC. Breaks
date_trunc function
----------------------------------+-----------------
     Reporter:  Mactory           |      Owner:
         Type:  Bug               |     Status:  new
    Component:  contrib.postgres  |    Version:  1.6
     Severity:  Normal            |   Keywords:
 Triage Stage:  Unreviewed        |  Has patch:  0
Easy pickings:  0                 |      UI/UX:  0
----------------------------------+-----------------
 When using a cursor created by  django.db.connection.cursor() to execute a
 database function on a postgresql database, the timezone of the database
 connection is always set to UTC instead of using the specified TIME_ZONE.
 This behavior brakes postgres' {{{ date_trunc }}} function, since it will
 truncate the hour to be 0 at UTC creating an offset from midnight at the
 local timestamp.

 Example:
 settings.py
 {{{
 TIME_ZONE = 'Europe/Berlin' # Offset +2
 USE_TZ = TRUE
 }}}

 using date_trunc in a djago python shell:
 {{{
 ./manage.py shell
 >>> from django.db import connection
 >>> cursor = connection.cursor()
 >>> cursor.execute("select date_trunc('month', TIMESTAMP WITH TIME ZONE
 '2014-09-14 04:10:00+02');")
 >>> unicode(cursor.fetchone()[0])
 u'2014-09-01 00:00:00+00:00'
 }}}

 using date_tunc directly in psql:
 {{{
 psql db
 db=#select date_trunc('month', TIMESTAMP WITH TIME ZONE '2014-09-14
 04:10:00+02');
        date_trunc
 ------------------------
  2014-09-01 00:00:00+02
 (1 row)
 }}}

 For executing custom functions for which no return value is needed, the
 following workaround does work:
 {{{
 >>> cursor.execute("SET TIMEZONE to %s;select date_trunc('month',
 TIMESTAMP WITH TIME ZONE '2014-09-14 04:10:00+02');SET TIMEZONE to
 'UTC';", (settings.TIME_ZONE,))
 }}}

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

Reply via email to