Skip to content

Commit 121188e

Browse files
committed
[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
1 parent 9405460 commit 121188e

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

django/db/backends/postgresql/base.py

Lines changed: 5 additions & 2 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -97,9 +97,11 @@ def __init__(self, *args, **kwargs):
97
self.validation = BaseDatabaseValidation()
97
self.validation = BaseDatabaseValidation()
98

98

99
def _cursor(self):
99
def _cursor(self):
100+
new_connection = False
100
set_tz = False
101
set_tz = False
101
settings_dict = self.settings_dict
102
settings_dict = self.settings_dict
102
if self.connection is None:
103
if self.connection is None:
104+
new_connection = True
103
set_tz = settings_dict.get('TIME_ZONE')
105
set_tz = settings_dict.get('TIME_ZONE')
104
if settings_dict['DATABASE_NAME'] == '':
106
if settings_dict['DATABASE_NAME'] == '':
105
from django.core.exceptions import ImproperlyConfigured
107
from django.core.exceptions import ImproperlyConfigured
@@ -117,8 +119,9 @@ def _cursor(self):
117
self.connection.set_isolation_level(1) # make transactions transparent to all cursors
119
self.connection.set_isolation_level(1) # make transactions transparent to all cursors
118
connection_created.send(sender=self.__class__)
120
connection_created.send(sender=self.__class__)
119
cursor = self.connection.cursor()
121
cursor = self.connection.cursor()
120-
if set_tz:
122+
if new_connection:
121-
cursor.execute("SET TIME ZONE %s", [settings_dict['TIME_ZONE']])
123+
if set_tz:
124+
cursor.execute("SET TIME ZONE %s", [settings_dict['TIME_ZONE']])
122
if not hasattr(self, '_version'):
125
if not hasattr(self, '_version'):
123
self.__class__._version = get_version(cursor)
126
self.__class__._version = get_version(cursor)
124
if self._version[0:2] < (8, 0):
127
if self._version[0:2] < (8, 0):

django/db/backends/postgresql_psycopg2/base.py

Lines changed: 5 additions & 2 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -74,9 +74,11 @@ def __init__(self, *args, **kwargs):
74
self.validation = BaseDatabaseValidation()
74
self.validation = BaseDatabaseValidation()
75

75

76
def _cursor(self):
76
def _cursor(self):
77+
new_connection = False
77
set_tz = False
78
set_tz = False
78
settings_dict = self.settings_dict
79
settings_dict = self.settings_dict
79
if self.connection is None:
80
if self.connection is None:
81+
new_connection = True
80
set_tz = settings_dict.get('TIME_ZONE')
82
set_tz = settings_dict.get('TIME_ZONE')
81
if settings_dict['DATABASE_NAME'] == '':
83
if settings_dict['DATABASE_NAME'] == '':
82
from django.core.exceptions import ImproperlyConfigured
84
from django.core.exceptions import ImproperlyConfigured
@@ -101,8 +103,9 @@ def _cursor(self):
101
connection_created.send(sender=self.__class__)
103
connection_created.send(sender=self.__class__)
102
cursor = self.connection.cursor()
104
cursor = self.connection.cursor()
103
cursor.tzinfo_factory = None
105
cursor.tzinfo_factory = None
104-
if set_tz:
106+
if new_connection:
105-
cursor.execute("SET TIME ZONE %s", [settings_dict['TIME_ZONE']])
107+
if set_tz:
108+
cursor.execute("SET TIME ZONE %s", [settings_dict['TIME_ZONE']])
106
if not hasattr(self, '_version'):
109
if not hasattr(self, '_version'):
107
self.__class__._version = get_version(cursor)
110
self.__class__._version = get_version(cursor)
108
if self._version[0:2] < (8, 0):
111
if self._version[0:2] < (8, 0):

0 commit comments

Comments
 (0)