diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py
index 74342e9..ebee623 100644
|
a
|
b
|
class DatabaseWrapper(BaseDatabaseWrapper):
|
| 109 | 109 | self.introspection = DatabaseIntrospection(self) |
| 110 | 110 | self.validation = BaseDatabaseValidation(self) |
| 111 | 111 | self._pg_version = None |
| | 112 | self.force_db_set = True |
| 112 | 113 | |
| 113 | 114 | def check_constraints(self, table_names=None): |
| 114 | 115 | """ |
| … |
… |
class DatabaseWrapper(BaseDatabaseWrapper):
|
| 143 | 144 | pg_version = property(_get_pg_version) |
| 144 | 145 | |
| 145 | 146 | def _cursor(self): |
| 146 | | new_connection = False |
| | 147 | force_db_set = self.force_db_set or self.connection is None |
| 147 | 148 | set_tz = False |
| 148 | 149 | settings_dict = self.settings_dict |
| 149 | | if self.connection is None: |
| 150 | | new_connection = True |
| | 150 | if force_db_set: |
| 151 | 151 | set_tz = settings_dict.get('TIME_ZONE') |
| 152 | 152 | if settings_dict['NAME'] == '': |
| 153 | 153 | from django.core.exceptions import ImproperlyConfigured |
| … |
… |
class DatabaseWrapper(BaseDatabaseWrapper):
|
| 172 | 172 | connection_created.send(sender=self.__class__, connection=self) |
| 173 | 173 | cursor = self.connection.cursor() |
| 174 | 174 | cursor.tzinfo_factory = None |
| 175 | | if new_connection: |
| | 175 | if force_db_set: |
| 176 | 176 | if set_tz: |
| 177 | | cursor.execute("SET TIME ZONE %s", [settings_dict['TIME_ZONE']]) |
| | 177 | self._set_tz(cursor, settings_dict['TIME_ZONE']) |
| 178 | 178 | self._get_pg_version() |
| | 179 | self.force_db_set = False |
| 179 | 180 | return CursorWrapper(cursor) |
| 180 | 181 | |
| | 182 | def _set_tz(self, cursor, tz): |
| | 183 | cursor.execute("SET TIME ZONE %s", [tz]) |
| | 184 | |
| 181 | 185 | def _enter_transaction_management(self, managed): |
| 182 | 186 | """ |
| 183 | 187 | Switch the isolation level when needing transaction support, so that |
diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py
index f2bd71d..e105367 100644
|
a
|
b
|
class BackendTestCase(TestCase):
|
| 308 | 308 | self.assertTrue(hasattr(connection.ops, 'connection')) |
| 309 | 309 | self.assertEqual(connection, connection.ops.connection) |
| 310 | 310 | |
| | 311 | @unittest.skipUnless(connection.vendor == 'postgresql', |
| | 312 | "SET TIME ZIME needs executed again if TIME_ZONE changes") |
| | 313 | def test_cursor_force_db_set(self): |
| | 314 | _set_tz = connection._set_tz |
| | 315 | def mock_set_tz(*args, **kwargs): |
| | 316 | mock_set_tz.called = (args, kwargs) |
| | 317 | mock_set_tz.called = False |
| | 318 | connection._set_tz = mock_set_tz |
| | 319 | try: |
| | 320 | connection.cursor() |
| | 321 | self.assert_(mock_set_tz.called) |
| | 322 | self.assertEqual(settings.TIME_ZONE, mock_set_tz.called[0][1]) |
| | 323 | mock_set_tz.called = False |
| | 324 | |
| | 325 | connection.cursor() |
| | 326 | self.assertFalse(mock_set_tz.called) |
| | 327 | mock_set_tz.called = False |
| | 328 | |
| | 329 | connection.force_db_set = True |
| | 330 | connection.cursor() |
| | 331 | self.assert_(mock_set_tz.called) |
| | 332 | self.assertEqual(settings.TIME_ZONE, mock_set_tz.called[0][1]) |
| | 333 | mock_set_tz.called = False |
| | 334 | |
| | 335 | finally: |
| | 336 | connection._set_tz = _set_tz |
| | 337 | |
| 311 | 338 | |
| 312 | 339 | # We don't make these tests conditional because that means we would need to |
| 313 | 340 | # check and differentiate between: |
diff --git a/tests/regressiontests/model_regress/tests.py b/tests/regressiontests/model_regress/tests.py
index 07ad8fa..0476193 100644
|
a
|
b
|
class ModelTests(TestCase):
|
| 148 | 148 | |
| 149 | 149 | @skipUnlessDBFeature("supports_timezones") |
| 150 | 150 | def test_timezones(self): |
| 151 | | # Saving an updating with timezone-aware datetime Python objects. |
| | 151 | # Saving and updating with timezone-aware datetime Python objects. |
| 152 | 152 | # Regression test for #10443. |
| 153 | 153 | # The idea is that all these creations and saving should work without |
| 154 | 154 | # crashing. It's not rocket science. |