Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#26177 closed Bug (fixed)

Using a Postgres database with TIME_ZONE set to None and USE_TZ set to False causes an exception

Reported by: Jensen Cochran Owned by: Tim Graham
Component: Database layer (models, ORM) Version: 1.8
Severity: Release blocker Keywords: postgres postgresql time zone time_zone TIME_ZONE=None
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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 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

Change History (7)

comment:1 Changed 4 years ago by Tim Graham

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

comment:2 Changed 4 years ago by Tim Graham

Owner: changed from nobody to Tim Graham
Status: newassigned

comment:3 Changed 4 years ago by Tim Graham

Has patch: set

comment:4 Changed 4 years ago by Claude Paroz

Triage Stage: AcceptedReady for checkin

comment:5 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 97eb3356:

Fixed #26177 -- Fixed a PostgreSQL crash with TIME_ZONE=None and USE_TZ=False.

comment:6 Changed 4 years ago by Tim Graham <timograham@…>

In 6b689a50:

[1.9.x] Fixed #26177 -- Fixed a PostgreSQL crash with TIME_ZONE=None and USE_TZ=False.

Backport of 97eb3356b2a7488c8d0ca0e47ef3e538852d44a2 from master

comment:7 Changed 4 years ago by Tim Graham <timograham@…>

In 2f0de9b:

[1.8.x] Fixed #26177 -- Fixed a PostgreSQL crash with TIME_ZONE=None and USE_TZ=False.

Backport of 97eb3356b2a7488c8d0ca0e47ef3e538852d44a2 from master

Note: See TracTickets for help on using tickets.
Back to Top