mirror of
https://github.com/inventree/InvenTree.git
synced 2026-04-15 07:48:51 +00:00
Improvements for data import (#11710)
- Do not double migrate if no plugin data imported - Prevent settings write on a settings read
This commit is contained in:
@@ -207,6 +207,14 @@ def readOnlyCommands():
|
||||
|
||||
def isReadOnlyCommand():
|
||||
"""Return True if the current command is a read-only command, which should not trigger any database writes."""
|
||||
if (
|
||||
isImportingData()
|
||||
or isRunningMigrations()
|
||||
or isRebuildingData()
|
||||
or isRunningBackup()
|
||||
):
|
||||
return True
|
||||
|
||||
return any(cmd in sys.argv for cmd in readOnlyCommands())
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ def global_setting_overrides() -> dict:
|
||||
|
||||
def get_global_setting(key, backup_value=None, environment_key=None, **kwargs):
|
||||
"""Return the value of a global setting using the provided key."""
|
||||
import InvenTree.ready
|
||||
from common.models import InvenTreeSetting
|
||||
|
||||
if environment_key:
|
||||
@@ -38,6 +39,10 @@ def get_global_setting(key, backup_value=None, environment_key=None, **kwargs):
|
||||
if backup_value is not None:
|
||||
kwargs['backup_value'] = backup_value
|
||||
|
||||
# Prevent database writes if we are in a read-only command
|
||||
if InvenTree.ready.isReadOnlyCommand():
|
||||
kwargs['create'] = False
|
||||
|
||||
return InvenTreeSetting.get_setting(key, **kwargs)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user