diff --git a/InvenTree/label/apps.py b/InvenTree/label/apps.py index 9d74917e54..9455d34a8b 100644 --- a/InvenTree/label/apps.py +++ b/InvenTree/label/apps.py @@ -10,10 +10,10 @@ from pathlib import Path from django.apps import AppConfig from django.conf import settings from django.core.exceptions import AppRegistryNotReady -from django.db.utils import OperationalError +from django.db.utils import IntegrityError, OperationalError, ProgrammingError -from InvenTree.ready import (canAppAccessDatabase, isInMainThread, - isPluginRegistryLoaded) +from InvenTree.ready import (canAppAccessDatabase, isImportingData, + isInMainThread, isPluginRegistryLoaded) logger = logging.getLogger("inventree") @@ -40,11 +40,10 @@ class LabelConfig(AppConfig): if not isPluginRegistryLoaded() or not isInMainThread(): return - if canAppAccessDatabase(allow_test=False): - + if canAppAccessDatabase(allow_test=False) and not isImportingData(): try: self.create_labels() # pragma: no cover - except (AppRegistryNotReady, OperationalError): + except (AppRegistryNotReady, IntegrityError, OperationalError, ProgrammingError): # Database might not yet be ready warnings.warn('Database was not ready for creating labels', stacklevel=2) diff --git a/InvenTree/report/apps.py b/InvenTree/report/apps.py index ac3f413e23..7f89348a2a 100644 --- a/InvenTree/report/apps.py +++ b/InvenTree/report/apps.py @@ -3,10 +3,13 @@ import logging import os import shutil +import warnings from pathlib import Path from django.apps import AppConfig from django.conf import settings +from django.core.exceptions import AppRegistryNotReady +from django.db.utils import IntegrityError, OperationalError, ProgrammingError logger = logging.getLogger("inventree") @@ -17,8 +20,8 @@ class ReportConfig(AppConfig): def ready(self): """This function is called whenever the report app is loaded.""" - from InvenTree.ready import (canAppAccessDatabase, isInMainThread, - isPluginRegistryLoaded) + from InvenTree.ready import (canAppAccessDatabase, isImportingData, + isInMainThread, isPluginRegistryLoaded) # skip loading if plugin registry is not loaded or we run in a background thread if not isPluginRegistryLoaded() or not isInMainThread(): @@ -29,14 +32,19 @@ class ReportConfig(AppConfig): logging.getLogger('weasyprint').setLevel(logging.WARNING) # Create entries for default report templates - if canAppAccessDatabase(allow_test=False): - self.create_default_test_reports() - self.create_default_build_reports() - self.create_default_bill_of_materials_reports() - self.create_default_purchase_order_reports() - self.create_default_sales_order_reports() - self.create_default_return_order_reports() - self.create_default_stock_location_reports() + if canAppAccessDatabase(allow_test=False) and not isImportingData(): + + try: + self.create_default_test_reports() + self.create_default_build_reports() + self.create_default_bill_of_materials_reports() + self.create_default_purchase_order_reports() + self.create_default_sales_order_reports() + self.create_default_return_order_reports() + self.create_default_stock_location_reports() + except (AppRegistryNotReady, IntegrityError, OperationalError, ProgrammingError): + # Database might not yet be ready + warnings.warn('Database was not ready for creating reports', stacklevel=2) def create_default_reports(self, model, reports): """Copy default report files across to the media directory."""