summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql_psycopg2/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/backends/postgresql_psycopg2/base.py')
-rw-r--r--django/db/backends/postgresql_psycopg2/base.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py
index 09b9eb4990..29b7e7ff1a 100644
--- a/django/db/backends/postgresql_psycopg2/base.py
+++ b/django/db/backends/postgresql_psycopg2/base.py
@@ -110,9 +110,11 @@ class DatabaseWrapper(BaseDatabaseWrapper):
self.validation = BaseDatabaseValidation(self)
def _cursor(self):
+ new_connection = False
set_tz = False
settings_dict = self.settings_dict
if self.connection is None:
+ new_connection = True
set_tz = settings_dict.get('TIME_ZONE')
if settings_dict['NAME'] == '':
from django.core.exceptions import ImproperlyConfigured
@@ -137,8 +139,9 @@ class DatabaseWrapper(BaseDatabaseWrapper):
connection_created.send(sender=self.__class__)
cursor = self.connection.cursor()
cursor.tzinfo_factory = None
- if set_tz:
- cursor.execute("SET TIME ZONE %s", [settings_dict['TIME_ZONE']])
+ if new_connection:
+ if set_tz:
+ cursor.execute("SET TIME ZONE %s", [settings_dict['TIME_ZONE']])
if not hasattr(self, '_version'):
self.__class__._version = get_version(cursor)
if self._version[0:2] < (8, 0):