diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2011-12-11 08:19:04 +0000 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2011-12-11 08:19:04 +0000 |
| commit | 219b41cc155a216fc912cd37f215fb44acee317b (patch) | |
| tree | 9d2b7ab8057a96dd5721776e7bce29bfff964bfb /django | |
| parent | d317f2ab984c6c1bd6755de99f9600bc8d9a5041 (diff) | |
Fixed #17266 -- Skipped the "SET TIME ZONE" query for PostgreSQL when it isn't necessary.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17194 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/backends/postgresql_psycopg2/base.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py index c81623720e..2f020f46cf 100644 --- a/django/db/backends/postgresql_psycopg2/base.py +++ b/django/db/backends/postgresql_psycopg2/base.py @@ -174,12 +174,21 @@ 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]) + 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: + # Set the time zone in autocommit mode (see #17062) + 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) |
