Refs #28478 -- Prevented timezone assignment for unusable PostgreSQL connections.
This commit is contained in:
parent
846624ed08
commit
a96b901932
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue