mirror of
https://github.com/inventree/InvenTree.git
synced 2026-04-13 14:58:47 +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)
|
||||
|
||||
|
||||
|
||||
4
tasks.py
4
tasks.py
@@ -1286,7 +1286,6 @@ def validate_import_metadata(
|
||||
'filename': 'Input filename',
|
||||
'clear': 'Clear existing data before import',
|
||||
'strict': 'Strict mode - fail if any issues are detected with the metadata (default = False)',
|
||||
'retain_temp': 'Retain temporary files at end of process (default = False)',
|
||||
'ignore_nonexistent': 'Ignore non-existent database models (default = False)',
|
||||
'exclude_plugins': 'Exclude plugin data from the import process (default = False)',
|
||||
'skip_migrations': 'Skip the migration step after clearing data (default = False)',
|
||||
@@ -1299,7 +1298,6 @@ def import_records(
|
||||
c,
|
||||
filename='data.json',
|
||||
clear: bool = False,
|
||||
retain_temp: bool = False,
|
||||
strict: bool = False,
|
||||
exclude_plugins: bool = False,
|
||||
ignore_nonexistent: bool = False,
|
||||
@@ -1423,8 +1421,8 @@ def import_records(
|
||||
if not exclude_plugins:
|
||||
load_data('plugins', plugin_data, app='plugin')
|
||||
|
||||
if len(plugin_data) > 0 and not skip_migrations:
|
||||
# Now that the plugins have been loaded, run database migrations again to ensure any new plugins have their database schema up to date
|
||||
if not skip_migrations:
|
||||
migrate(c)
|
||||
|
||||
# Run validation again - ensure that the plugin apps have been loaded correctly
|
||||
|
||||
Reference in New Issue
Block a user