diff --git a/src/backend/InvenTree/InvenTree/ready.py b/src/backend/InvenTree/InvenTree/ready.py index da850b5285..0a87e8d616 100644 --- a/src/backend/InvenTree/InvenTree/ready.py +++ b/src/backend/InvenTree/InvenTree/ready.py @@ -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()) diff --git a/src/backend/InvenTree/common/settings.py b/src/backend/InvenTree/common/settings.py index 687d3fecf7..0bccd1b1ec 100644 --- a/src/backend/InvenTree/common/settings.py +++ b/src/backend/InvenTree/common/settings.py @@ -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) diff --git a/tasks.py b/tasks.py index d9380bea12..9f8886646a 100644 --- a/tasks.py +++ b/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') - # 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: + 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 migrate(c) # Run validation again - ensure that the plugin apps have been loaded correctly