Better exception handling

This commit is contained in:
Oliver Walters 2021-05-28 13:02:34 +10:00
parent 7832ccccc2
commit be6e2aa276
2 changed files with 19 additions and 2 deletions

View File

@ -6,7 +6,7 @@ from django.apps import AppConfig
from django.core.exceptions import AppRegistryNotReady
from django.conf import settings
from InvenTree.ready import canAppAccessDatabase
from InvenTree.ready import isInTestMode, canAppAccessDatabase
import InvenTree.tasks
@ -20,7 +20,9 @@ class InvenTreeConfig(AppConfig):
if canAppAccessDatabase():
self.start_background_tasks()
self.update_exchange_rates()
if not isInTestMode():
self.update_exchange_rates()
def start_background_tasks(self):
@ -95,5 +97,9 @@ class InvenTreeConfig(AppConfig):
print("Exchange backend not found - updating")
update = True
except:
# Some other error - potentially the tables are not ready yet
return
if update:
update_exchange_rates()

View File

@ -1,6 +1,17 @@
import sys
def isInTestMode():
"""
Returns True if the database is in testing mode
"""
if 'test' in sys.argv:
return True
return False
def canAppAccessDatabase():
"""
Returns True if the apps.py file can access database records.