summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2015-02-14 09:53:17 +0100
committerTim Graham <timograham@gmail.com>2015-02-17 06:21:24 -0500
commit30e5356c2ecb220e0ac866a7860aefbc90b97aa0 (patch)
tree16f5b48ded1d710cfc9bbfc6681aa1cdf9453f1b
parent2b79a35a830cf5326b1c764963b7e8431864ec97 (diff)
[1.8.x] Cleaned up init_connection_state in the psycopg2 backend.
settings_dict['TIME_ZONE'] is set in ConnectionHandler.ensure_defaults. Backport of 28e97a9bdc6c672a1304570aa75f6311fb1112e2 from master
-rw-r--r--django/db/backends/postgresql_psycopg2/base.py37
1 files changed, 18 insertions, 19 deletions
diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py
index d2e114fea5..2efb904997 100644
--- a/django/db/backends/postgresql_psycopg2/base.py
+++ b/django/db/backends/postgresql_psycopg2/base.py
@@ -186,27 +186,26 @@ class DatabaseWrapper(BaseDatabaseWrapper):
return connection
def init_connection_state(self):
- settings_dict = self.settings_dict
self.connection.set_client_encoding('UTF8')
- tz = 'UTC' if settings.USE_TZ else settings_dict.get('TIME_ZONE')
- if tz:
- try:
- get_parameter_status = self.connection.get_parameter_status
- except AttributeError:
- # psycopg2 < 2.0.12 doesn't have get_parameter_status
- conn_tz = None
- else:
- conn_tz = get_parameter_status('TimeZone')
- if conn_tz != tz:
- cursor = self.connection.cursor()
- try:
- cursor.execute(self.ops.set_time_zone_sql(), [tz])
- finally:
- cursor.close()
- # Commit after setting the time zone (see #17062)
- if not self.get_autocommit():
- self.connection.commit()
+ tz = self.settings_dict['TIME_ZONE']
+ try:
+ get_parameter_status = self.connection.get_parameter_status
+ except AttributeError:
+ # psycopg2 < 2.0.12 doesn't have get_parameter_status
+ conn_tz = None
+ else:
+ conn_tz = get_parameter_status('TimeZone')
+
+ if conn_tz != tz:
+ cursor = self.connection.cursor()
+ try:
+ cursor.execute(self.ops.set_time_zone_sql(), [tz])
+ finally:
+ cursor.close()
+ # Commit after setting the time zone (see #17062)
+ if not self.get_autocommit():
+ self.connection.commit()
def create_cursor(self):
cursor = self.connection.cursor()