mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Ready fix (#6191)
* Update "isRunningMigrations" method * Update other apps.py files
This commit is contained in:
parent
e1b670ba57
commit
445551e6f3
@ -12,10 +12,9 @@ from django.db import transaction
|
||||
from django.db.utils import IntegrityError, OperationalError
|
||||
|
||||
import InvenTree.conversion
|
||||
import InvenTree.ready
|
||||
import InvenTree.tasks
|
||||
from InvenTree.config import get_setting
|
||||
from InvenTree.ready import (canAppAccessDatabase, isInMainThread,
|
||||
isInTestMode, isPluginRegistryLoaded)
|
||||
|
||||
logger = logging.getLogger("inventree")
|
||||
|
||||
@ -37,17 +36,21 @@ class InvenTreeConfig(AppConfig):
|
||||
- Adding users set in the current environment
|
||||
"""
|
||||
# skip loading if plugin registry is not loaded or we run in a background thread
|
||||
if not isPluginRegistryLoaded() or not isInMainThread():
|
||||
if not InvenTree.ready.isPluginRegistryLoaded() or not InvenTree.ready.isInMainThread():
|
||||
return
|
||||
|
||||
if canAppAccessDatabase() or settings.TESTING_ENV:
|
||||
# Skip if running migrations
|
||||
if InvenTree.ready.isRunningMigrations():
|
||||
return
|
||||
|
||||
if InvenTree.ready.canAppAccessDatabase() or settings.TESTING_ENV:
|
||||
|
||||
self.remove_obsolete_tasks()
|
||||
|
||||
self.collect_tasks()
|
||||
self.start_background_tasks()
|
||||
|
||||
if not isInTestMode(): # pragma: no cover
|
||||
if not InvenTree.ready.isInTestMode(): # pragma: no cover
|
||||
self.update_exchange_rates()
|
||||
# Let the background worker check for migrations
|
||||
InvenTree.tasks.offload_task(InvenTree.tasks.check_for_migrations)
|
||||
@ -58,7 +61,7 @@ class InvenTreeConfig(AppConfig):
|
||||
# Ensure the unit registry is loaded
|
||||
InvenTree.conversion.get_unit_registry()
|
||||
|
||||
if canAppAccessDatabase() or settings.TESTING_ENV:
|
||||
if InvenTree.ready.canAppAccessDatabase() or settings.TESTING_ENV:
|
||||
self.add_user_on_startup()
|
||||
self.add_user_from_file()
|
||||
|
||||
|
@ -16,7 +16,11 @@ def isImportingData():
|
||||
|
||||
def isRunningMigrations():
|
||||
"""Return True if the database is currently running migrations."""
|
||||
return 'migrate' in sys.argv or 'makemigrations' in sys.argv
|
||||
return any((x in sys.argv for x in [
|
||||
'migrate',
|
||||
'makemigrations',
|
||||
'showmigrations'
|
||||
]))
|
||||
|
||||
|
||||
def isInMainThread():
|
||||
|
@ -4,7 +4,7 @@ import logging
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
from InvenTree.ready import isImportingData
|
||||
import InvenTree.ready
|
||||
|
||||
logger = logging.getLogger('inventree')
|
||||
|
||||
@ -19,6 +19,10 @@ class CommonConfig(AppConfig):
|
||||
|
||||
def ready(self):
|
||||
"""Initialize restart flag clearance on startup."""
|
||||
|
||||
if InvenTree.ready.isRunningMigrations():
|
||||
return
|
||||
|
||||
self.clear_restart_flag()
|
||||
|
||||
def clear_restart_flag(self):
|
||||
@ -29,7 +33,7 @@ class CommonConfig(AppConfig):
|
||||
if common.models.InvenTreeSetting.get_setting('SERVER_RESTART_REQUIRED', backup_value=False, create=False, cache=False):
|
||||
logger.info("Clearing SERVER_RESTART_REQUIRED flag")
|
||||
|
||||
if not isImportingData():
|
||||
if not InvenTree.ready.isImportingData():
|
||||
common.models.InvenTreeSetting.set_setting('SERVER_RESTART_REQUIRED', False, None)
|
||||
except Exception:
|
||||
pass
|
||||
|
@ -12,8 +12,7 @@ from django.conf import settings
|
||||
from django.core.exceptions import AppRegistryNotReady
|
||||
from django.db.utils import IntegrityError, OperationalError, ProgrammingError
|
||||
|
||||
from InvenTree.ready import (canAppAccessDatabase, isImportingData,
|
||||
isInMainThread, isPluginRegistryLoaded)
|
||||
import InvenTree.ready
|
||||
|
||||
logger = logging.getLogger("inventree")
|
||||
|
||||
@ -37,10 +36,13 @@ class LabelConfig(AppConfig):
|
||||
def ready(self):
|
||||
"""This function is called whenever the label app is loaded."""
|
||||
# skip loading if plugin registry is not loaded or we run in a background thread
|
||||
if not isPluginRegistryLoaded() or not isInMainThread():
|
||||
if not InvenTree.ready.isPluginRegistryLoaded() or not InvenTree.ready.isInMainThread():
|
||||
return
|
||||
|
||||
if canAppAccessDatabase(allow_test=False) and not isImportingData():
|
||||
if InvenTree.ready.isRunningMigrations():
|
||||
return
|
||||
|
||||
if InvenTree.ready.canAppAccessDatabase(allow_test=False) and not InvenTree.ready.isImportingData():
|
||||
try:
|
||||
self.create_labels() # pragma: no cover
|
||||
except (AppRegistryNotReady, IntegrityError, OperationalError, ProgrammingError):
|
||||
|
@ -5,8 +5,7 @@ import logging
|
||||
from django.apps import AppConfig
|
||||
from django.db.utils import OperationalError, ProgrammingError
|
||||
|
||||
from InvenTree.ready import (canAppAccessDatabase, isImportingData,
|
||||
isInMainThread, isPluginRegistryLoaded)
|
||||
import InvenTree.ready
|
||||
|
||||
logger = logging.getLogger("inventree")
|
||||
|
||||
@ -18,10 +17,13 @@ class PartConfig(AppConfig):
|
||||
def ready(self):
|
||||
"""This function is called whenever the Part app is loaded."""
|
||||
# skip loading if plugin registry is not loaded or we run in a background thread
|
||||
if not isPluginRegistryLoaded() or not isInMainThread():
|
||||
if not InvenTree.ready.isPluginRegistryLoaded() or not InvenTree.ready.isInMainThread():
|
||||
return
|
||||
|
||||
if canAppAccessDatabase():
|
||||
if InvenTree.ready.isRunningMigrations():
|
||||
return
|
||||
|
||||
if InvenTree.ready.canAppAccessDatabase():
|
||||
self.update_trackable_status()
|
||||
self.reset_part_pricing_flags()
|
||||
|
||||
@ -51,7 +53,7 @@ class PartConfig(AppConfig):
|
||||
"""
|
||||
from .models import PartPricing
|
||||
|
||||
if isImportingData():
|
||||
if InvenTree.ready.isImportingData():
|
||||
return
|
||||
|
||||
try:
|
||||
|
@ -20,11 +20,13 @@ class ReportConfig(AppConfig):
|
||||
|
||||
def ready(self):
|
||||
"""This function is called whenever the report app is loaded."""
|
||||
from InvenTree.ready import (canAppAccessDatabase, isImportingData,
|
||||
isInMainThread, isPluginRegistryLoaded)
|
||||
import InvenTree.ready
|
||||
|
||||
# skip loading if plugin registry is not loaded or we run in a background thread
|
||||
if not isPluginRegistryLoaded() or not isInMainThread():
|
||||
if not InvenTree.ready.isPluginRegistryLoaded() or not InvenTree.ready.isInMainThread():
|
||||
return
|
||||
|
||||
if InvenTree.ready.isRunningMigrations():
|
||||
return
|
||||
|
||||
# Configure logging for PDF generation (disable "info" messages)
|
||||
@ -32,7 +34,7 @@ class ReportConfig(AppConfig):
|
||||
logging.getLogger('weasyprint').setLevel(logging.WARNING)
|
||||
|
||||
# Create entries for default report templates
|
||||
if canAppAccessDatabase(allow_test=False) and not isImportingData():
|
||||
if InvenTree.ready.canAppAccessDatabase(allow_test=False) and not InvenTree.ready.isImportingData():
|
||||
|
||||
try:
|
||||
self.create_default_test_reports()
|
||||
|
@ -5,8 +5,7 @@ import logging
|
||||
from django.apps import AppConfig
|
||||
from django.db.utils import OperationalError, ProgrammingError
|
||||
|
||||
from InvenTree.ready import (canAppAccessDatabase, isInMainThread,
|
||||
isPluginRegistryLoaded)
|
||||
import InvenTree.ready
|
||||
|
||||
logger = logging.getLogger('inventree')
|
||||
|
||||
@ -19,10 +18,14 @@ class UsersConfig(AppConfig):
|
||||
def ready(self):
|
||||
"""Called when the 'users' app is loaded at runtime"""
|
||||
# skip loading if plugin registry is not loaded or we run in a background thread
|
||||
if not isPluginRegistryLoaded() or not isInMainThread():
|
||||
if not InvenTree.ready.isPluginRegistryLoaded() or not InvenTree.ready.isInMainThread():
|
||||
return
|
||||
|
||||
if canAppAccessDatabase(allow_test=True):
|
||||
# Skip if running migrations
|
||||
if InvenTree.ready.isRunningMigrations():
|
||||
return
|
||||
|
||||
if InvenTree.ready.canAppAccessDatabase(allow_test=True):
|
||||
|
||||
try:
|
||||
self.assign_permissions()
|
||||
|
Loading…
Reference in New Issue
Block a user