Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[1.1.X] Corrected an edge case introduced in r12602. Thanks to Ramiro…
… Morales for the eagle eyes.

Backport of r12605 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12606 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
freakboy3742 committed Feb 26, 2010
1 parent 9405460 commit 121188e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions django/db/backends/postgresql/base.py
Expand Up @@ -97,9 +97,11 @@ def __init__(self, *args, **kwargs):
self.validation = BaseDatabaseValidation() self.validation = BaseDatabaseValidation()


def _cursor(self): def _cursor(self):
new_connection = False
set_tz = False set_tz = False
settings_dict = self.settings_dict settings_dict = self.settings_dict
if self.connection is None: if self.connection is None:
new_connection = True
set_tz = settings_dict.get('TIME_ZONE') set_tz = settings_dict.get('TIME_ZONE')
if settings_dict['DATABASE_NAME'] == '': if settings_dict['DATABASE_NAME'] == '':
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
Expand All @@ -117,8 +119,9 @@ def _cursor(self):
self.connection.set_isolation_level(1) # make transactions transparent to all cursors self.connection.set_isolation_level(1) # make transactions transparent to all cursors
connection_created.send(sender=self.__class__) connection_created.send(sender=self.__class__)
cursor = self.connection.cursor() cursor = self.connection.cursor()
if set_tz: if new_connection:
cursor.execute("SET TIME ZONE %s", [settings_dict['TIME_ZONE']]) if set_tz:
cursor.execute("SET TIME ZONE %s", [settings_dict['TIME_ZONE']])
if not hasattr(self, '_version'): if not hasattr(self, '_version'):
self.__class__._version = get_version(cursor) self.__class__._version = get_version(cursor)
if self._version[0:2] < (8, 0): if self._version[0:2] < (8, 0):
Expand Down
7 changes: 5 additions & 2 deletions django/db/backends/postgresql_psycopg2/base.py
Expand Up @@ -74,9 +74,11 @@ def __init__(self, *args, **kwargs):
self.validation = BaseDatabaseValidation() self.validation = BaseDatabaseValidation()


def _cursor(self): def _cursor(self):
new_connection = False
set_tz = False set_tz = False
settings_dict = self.settings_dict settings_dict = self.settings_dict
if self.connection is None: if self.connection is None:
new_connection = True
set_tz = settings_dict.get('TIME_ZONE') set_tz = settings_dict.get('TIME_ZONE')
if settings_dict['DATABASE_NAME'] == '': if settings_dict['DATABASE_NAME'] == '':
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
Expand All @@ -101,8 +103,9 @@ def _cursor(self):
connection_created.send(sender=self.__class__) connection_created.send(sender=self.__class__)
cursor = self.connection.cursor() cursor = self.connection.cursor()
cursor.tzinfo_factory = None cursor.tzinfo_factory = None
if set_tz: if new_connection:
cursor.execute("SET TIME ZONE %s", [settings_dict['TIME_ZONE']]) if set_tz:
cursor.execute("SET TIME ZONE %s", [settings_dict['TIME_ZONE']])
if not hasattr(self, '_version'): if not hasattr(self, '_version'):
self.__class__._version = get_version(cursor) self.__class__._version = get_version(cursor)
if self._version[0:2] < (8, 0): if self._version[0:2] < (8, 0):
Expand Down

0 comments on commit 121188e

Please sign in to comment.