[Django] #26177: Using a Postgres database with TIME_ZONE set to None and USE_TZ set to False causes an exception

4 views
Skip to first unread message

Django

unread,
Feb 4, 2016, 2:12:20 PM2/4/16
to django-...@googlegroups.com
#26177: Using a Postgres database with TIME_ZONE set to None and USE_TZ set to
False causes an exception
-------------------------------------+-------------------------------------
Reporter: jensen-cochran | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) | Keywords: postgres postgresql
Severity: Normal | time zone time_zone TIME_ZONE=None
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
You are supposed to be able to set TIME_ZONE = None and USE_TZ = False in
order to the use the system time (if you are not on Windows). When using a
Postgres database, this functionality is broken in 1.8 onward and causes
an exception to occur when the development server is started.

The bottom part of the stack trace looks like this:
{{{
File "/usr/lib64/python2.7/site-packages/django/db/backends/base/base.py",
line 121, in connect
self.init_connection_state()
File "/usr/lib64/python2.7/site-
packages/django/db/backends/postgresql_psycopg2/base.py", line 204, in
init_connection_state
cursor.execute(self.ops.set_time_zone_sql(), [tz])
django.db.utils.ProgrammingError: syntax error at or near "NULL"
}}}

What is happening is that self.init_connection_state() is not checking
whether or not the tz setting is None, so None is being formatted into the
SQL string inside of self.ops.set_time_zone_sql() to get "SET TIME ZONE
NULL".

Before 1.8, there was a check in place to make sure that tz was truthy
before proceeding, but it was removed in
[[https://github.com/django/django/commit/30e5356c2ecb220e0ac866a7860aefbc90b97aa0?diff=split|this
commit]].

You can reproduce this bug simply by making a new Django project and
setting TIME_ZONE = None, USE_TZ = False, and setting the default database
to a postgres database.

Tested on Django 1.8.0, 1.8.9, and 1.9.2 using PostgreSQL 9.2.9 and Python
2.7.3 on CentOS 6.5

--
Ticket URL: <https://code.djangoproject.com/ticket/26177>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 4, 2016, 7:26:39 PM2/4/16
to django-...@googlegroups.com
#26177: Using a Postgres database with TIME_ZONE set to None and USE_TZ set to
False causes an exception
-------------------------------------+-------------------------------------
Reporter: jensen-cochran | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: postgres postgresql | Triage Stage: Accepted
time zone time_zone |
TIME_ZONE=None |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* needs_docs: => 0
* severity: Normal => Release blocker
* needs_tests: => 0
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/26177#comment:1>

Django

unread,
Feb 6, 2016, 9:07:19 AM2/6/16
to django-...@googlegroups.com
#26177: Using a Postgres database with TIME_ZONE set to None and USE_TZ set to
False causes an exception
-------------------------------------+-------------------------------------
Reporter: jensen-cochran | Owner: timgraham
Type: Bug | Status: assigned

Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: postgres postgresql | Triage Stage: Accepted
time zone time_zone |
TIME_ZONE=None |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* owner: nobody => timgraham
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/26177#comment:2>

Django

unread,
Feb 6, 2016, 10:08:34 AM2/6/16
to django-...@googlegroups.com
#26177: Using a Postgres database with TIME_ZONE set to None and USE_TZ set to
False causes an exception
-------------------------------------+-------------------------------------
Reporter: jensen-cochran | Owner: timgraham
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: postgres postgresql | Triage Stage: Accepted
time zone time_zone |
TIME_ZONE=None |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/6096 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/26177#comment:3>

Django

unread,
Feb 8, 2016, 6:00:30 AM2/8/16
to django-...@googlegroups.com
#26177: Using a Postgres database with TIME_ZONE set to None and USE_TZ set to
False causes an exception
-------------------------------------+-------------------------------------
Reporter: jensen-cochran | Owner: timgraham
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: postgres postgresql | Triage Stage: Ready for
time zone time_zone | checkin

TIME_ZONE=None |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by claudep):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/26177#comment:4>

Django

unread,
Feb 8, 2016, 7:40:50 AM2/8/16
to django-...@googlegroups.com
#26177: Using a Postgres database with TIME_ZONE set to None and USE_TZ set to
False causes an exception
-------------------------------------+-------------------------------------
Reporter: jensen-cochran | Owner: timgraham
Type: Bug | Status: closed

Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution: fixed

Keywords: postgres postgresql | Triage Stage: Ready for
time zone time_zone | checkin
TIME_ZONE=None |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"97eb3356b2a7488c8d0ca0e47ef3e538852d44a2" 97eb3356]:
{{{
#!CommitTicketReference repository=""
revision="97eb3356b2a7488c8d0ca0e47ef3e538852d44a2"
Fixed #26177 -- Fixed a PostgreSQL crash with TIME_ZONE=None and
USE_TZ=False.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26177#comment:5>

Django

unread,
Feb 8, 2016, 7:42:54 AM2/8/16
to django-...@googlegroups.com
#26177: Using a Postgres database with TIME_ZONE set to None and USE_TZ set to
False causes an exception
-------------------------------------+-------------------------------------
Reporter: jensen-cochran | Owner: timgraham
Type: Bug | Status: closed
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: postgres postgresql | Triage Stage: Ready for
time zone time_zone | checkin
TIME_ZONE=None |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"6b689a505c7a89d497e2e8af690fdf5a00780a2d" 6b689a50]:
{{{
#!CommitTicketReference repository=""
revision="6b689a505c7a89d497e2e8af690fdf5a00780a2d"
[1.9.x] Fixed #26177 -- Fixed a PostgreSQL crash with TIME_ZONE=None and
USE_TZ=False.

Backport of 97eb3356b2a7488c8d0ca0e47ef3e538852d44a2 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26177#comment:6>

Django

unread,
Feb 8, 2016, 7:50:48 AM2/8/16
to django-...@googlegroups.com
#26177: Using a Postgres database with TIME_ZONE set to None and USE_TZ set to
False causes an exception
-------------------------------------+-------------------------------------
Reporter: jensen-cochran | Owner: timgraham
Type: Bug | Status: closed
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: postgres postgresql | Triage Stage: Ready for
time zone time_zone | checkin
TIME_ZONE=None |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"2f0de9b0a1c30368bb6e81dd811dee88c327ae73" 2f0de9b]:
{{{
#!CommitTicketReference repository=""
revision="2f0de9b0a1c30368bb6e81dd811dee88c327ae73"
[1.8.x] Fixed #26177 -- Fixed a PostgreSQL crash with TIME_ZONE=None and
USE_TZ=False.

Backport of 97eb3356b2a7488c8d0ca0e47ef3e538852d44a2 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26177#comment:7>

Reply all
Reply to author
Forward
0 new messages