mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 12:36:45 +00:00
Allow setting to be checked without being created
- Prevents crash when trying to load exported dataset
This commit is contained in:
parent
7f888923c8
commit
39e8b2af0f
@ -23,7 +23,7 @@ class CommonConfig(AppConfig):
|
|||||||
try:
|
try:
|
||||||
import common.models
|
import common.models
|
||||||
|
|
||||||
if common.models.InvenTreeSetting.get_setting('SERVER_RESTART_REQUIRED'):
|
if common.models.InvenTreeSetting.get_setting('SERVER_RESTART_REQUIRED', backup_value=False, create=False):
|
||||||
logger.info("Clearing SERVER_RESTART_REQUIRED flag")
|
logger.info("Clearing SERVER_RESTART_REQUIRED flag")
|
||||||
common.models.InvenTreeSetting.set_setting('SERVER_RESTART_REQUIRED', False, None)
|
common.models.InvenTreeSetting.set_setting('SERVER_RESTART_REQUIRED', False, None)
|
||||||
except:
|
except:
|
||||||
|
@ -268,20 +268,24 @@ class BaseInvenTreeSetting(models.Model):
|
|||||||
# Setting does not exist! (Try to create it)
|
# Setting does not exist! (Try to create it)
|
||||||
if not setting:
|
if not setting:
|
||||||
|
|
||||||
# Attempt to create a new settings object
|
# Unless otherwise specified, attempt to create the setting
|
||||||
setting = cls(
|
create = kwargs.get('create', True)
|
||||||
key=key,
|
|
||||||
value=cls.get_setting_default(key, **kwargs),
|
|
||||||
**kwargs
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
if create:
|
||||||
# Wrap this statement in "atomic", so it can be rolled back if it fails
|
# Attempt to create a new settings object
|
||||||
with transaction.atomic():
|
setting = cls(
|
||||||
setting.save()
|
key=key,
|
||||||
except (IntegrityError, OperationalError):
|
value=cls.get_setting_default(key, **kwargs),
|
||||||
# It might be the case that the database isn't created yet
|
**kwargs
|
||||||
pass
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Wrap this statement in "atomic", so it can be rolled back if it fails
|
||||||
|
with transaction.atomic():
|
||||||
|
setting.save()
|
||||||
|
except (IntegrityError, OperationalError):
|
||||||
|
# It might be the case that the database isn't created yet
|
||||||
|
pass
|
||||||
|
|
||||||
return setting
|
return setting
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user