diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2011-11-20 16:12:33 +0000 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2011-11-20 16:12:33 +0000 |
| commit | 74b836abf541bb83047c5f07fbb6f49783d46475 (patch) | |
| tree | 656bdc5327ca6d2f8f25eabb8113a4dc674b1e06 /django | |
| parent | 98b08bd4d449f5e32c53e498f6ba3f019b6b5191 (diff) | |
Fixed #17062 -- Ensured that the effect of SET TIME ZONE isn't lost when the first transation is rolled back under PostgreSQL. Thanks Anssi for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17128 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/backends/postgresql_psycopg2/base.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py index dbd49c55e1..c81623720e 100644 --- a/django/db/backends/postgresql_psycopg2/base.py +++ b/django/db/backends/postgresql_psycopg2/base.py @@ -153,10 +153,8 @@ class DatabaseWrapper(BaseDatabaseWrapper): pg_version = property(_get_pg_version) def _cursor(self): - new_connection = False settings_dict = self.settings_dict if self.connection is None: - new_connection = True if settings_dict['NAME'] == '': from django.core.exceptions import ImproperlyConfigured raise ImproperlyConfigured("You need to specify NAME in your Django settings file.") @@ -176,15 +174,17 @@ class DatabaseWrapper(BaseDatabaseWrapper): conn_params['port'] = settings_dict['PORT'] self.connection = Database.connect(**conn_params) self.connection.set_client_encoding('UTF8') + # Set the time zone in autocommit mode (see #17062) + tz = 'UTC' if settings.USE_TZ else settings_dict.get('TIME_ZONE') + if tz: + self.connection.set_isolation_level( + psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) + self.connection.cursor().execute("SET TIME ZONE %s", [tz]) self.connection.set_isolation_level(self.isolation_level) + self._get_pg_version() connection_created.send(sender=self.__class__, connection=self) cursor = self.connection.cursor() cursor.tzinfo_factory = utc_tzinfo_factory if settings.USE_TZ else None - if new_connection: - tz = 'UTC' if settings.USE_TZ else settings_dict.get('TIME_ZONE') - if tz: - cursor.execute("SET TIME ZONE %s", [tz]) - self._get_pg_version() return CursorWrapper(cursor) def _enter_transaction_management(self, managed): |
