File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
src/ansys/dynamicreporting/core/utils Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -1005,6 +1005,9 @@ def create_new_local_database(
10051005
10061006 return False
10071007
1008+ # Check for Linux TZ issue
1009+ report_utils .apply_timezone_workaround ()
1010+
10081011 try :
10091012 if run_local :
10101013 # Make a random string that could be used as a secret key for the database
@@ -1348,6 +1351,9 @@ def launch_local_database_server(
13481351 if return_info is None :
13491352 return_info = dict ()
13501353
1354+ # Check for Linux TZ issue
1355+ report_utils .apply_timezone_workaround ()
1356+
13511357 # Try to use a lock file to prevent port scanning collisions
13521358 # We create a lockfiles in the user's home directory. Under windows, we use LOCALAPPDATA to avoid
13531359 # the case where a home dir may be mounted remotely, potentially causing permission issues when writing.
Original file line number Diff line number Diff line change @@ -739,3 +739,35 @@ def get_links_from_html(html):
739739 parser = HTMLParser ()
740740 parser .feed (html )
741741 return parser .links
742+
743+
744+ def apply_timezone_workaround () -> None :
745+ """
746+ Apply a workaround for known Linux system misconfigurations.
747+
748+ There is a known issue on some Linux systems where the timezone configuration is
749+ incorrect. On these systems, the get_localzone_name() call will raise an exception
750+ that prevents a Django instance from starting. This effects the Nexus server as
751+ well as the adr API for doing things like creating a database.
752+
753+ The work-around is to try to trigger the exception early and (on failure) set the TZ
754+ environmental variable to a known value and warn the user that this has been done.
755+ If the user sets TZ or corrects the system misconfiguration, that will also fix the
756+ issue.
757+ """
758+ try :
759+ # Attempt to trigger the misconfiguration issue.
760+ import tzlocal
761+
762+ _ = tzlocal .get_localzone_name ()
763+ except ModuleNotFoundError :
764+ # tzlocal is only used by the Django code, so if it is not present,
765+ return
766+ except KeyError as e :
767+ # Issue a warning
768+ import warnings
769+
770+ msg = "The timezone of this session is not configured correctly, trying 'US/Eastern' : "
771+ warnings .warn (msg + str (e ))
772+ # Try a relatively well known TZ
773+ os .environ ["TZ" ] = "US/Eastern"
You can’t perform that action at this time.
0 commit comments