summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql/base.py
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2019-01-12 14:17:36 -0500
committerTim Graham <timograham@gmail.com>2019-01-14 16:05:00 -0500
commita96b9019320ed8236659ee520a7a017c1bafbc6f (patch)
treeea8b2511bc7023ccd0982ef8c8c90b755b84e3f4 /django/db/backends/postgresql/base.py
parent846624ed0858aec0e51baebaa5b397e135c6d1dc (diff)
downloaddjango-a96b9019320ed8236659ee520a7a017c1bafbc6f.tar.gz
Refs #28478 -- Prevented timezone assignment for unusable PostgreSQL connections.
Diffstat (limited to 'django/db/backends/postgresql/base.py')
-rw-r--r--django/db/backends/postgresql/base.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py
index 9de9b44735..e9db668a4d 100644
--- a/django/db/backends/postgresql/base.py
+++ b/django/db/backends/postgresql/base.py
@@ -195,7 +195,8 @@ class DatabaseWrapper(BaseDatabaseWrapper):
return connection
def ensure_timezone(self):
- self.ensure_connection()
+ if not self.is_usable():
+ return False
conn_timezone_name = self.connection.get_parameter_status('TimeZone')
timezone_name = self.timezone_name
if timezone_name and conn_timezone_name != timezone_name:
@@ -207,6 +208,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
def init_connection_state(self):
self.connection.set_client_encoding('UTF8')
+ self.ensure_connection()
timezone_changed = self.ensure_timezone()
if timezone_changed:
# Commit after setting the time zone (see #17062)
@@ -246,6 +248,8 @@ class DatabaseWrapper(BaseDatabaseWrapper):
self.cursor().execute('SET CONSTRAINTS ALL DEFERRED')
def is_usable(self):
+ if self.connection is None:
+ return False
try:
# Use a psycopg cursor directly, bypassing Django's utilities.
self.connection.cursor().execute("SELECT 1")