mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 12:06:44 +00:00
Exception handling (#5622)
* get_setting_object: Handle ProgrammingError * Improved exception handling - Address a few cases on application startup if the database is not ready (migrations not applied)
This commit is contained in:
parent
2b0d81fd81
commit
08e7190832
@ -71,7 +71,10 @@ class InvenTreeConfig(AppConfig):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Remove any existing obsolete tasks
|
# Remove any existing obsolete tasks
|
||||||
Schedule.objects.filter(func__in=obsolete).delete()
|
try:
|
||||||
|
Schedule.objects.filter(func__in=obsolete).delete()
|
||||||
|
except Exception:
|
||||||
|
logger.error("Failed to remove obsolete tasks - database not ready")
|
||||||
|
|
||||||
def start_background_tasks(self):
|
def start_background_tasks(self):
|
||||||
"""Start all background tests for InvenTree."""
|
"""Start all background tests for InvenTree."""
|
||||||
|
@ -31,7 +31,7 @@ from django.core.validators import (MaxValueValidator, MinValueValidator,
|
|||||||
URLValidator)
|
URLValidator)
|
||||||
from django.db import models, transaction
|
from django.db import models, transaction
|
||||||
from django.db.models.signals import post_delete, post_save
|
from django.db.models.signals import post_delete, post_save
|
||||||
from django.db.utils import IntegrityError, OperationalError
|
from django.db.utils import IntegrityError, OperationalError, ProgrammingError
|
||||||
from django.dispatch.dispatcher import receiver
|
from django.dispatch.dispatcher import receiver
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
@ -487,7 +487,7 @@ class BaseInvenTreeSetting(models.Model):
|
|||||||
setting = settings.filter(**filters).first()
|
setting = settings.filter(**filters).first()
|
||||||
except (ValueError, cls.DoesNotExist):
|
except (ValueError, cls.DoesNotExist):
|
||||||
setting = None
|
setting = None
|
||||||
except (IntegrityError, OperationalError):
|
except (IntegrityError, OperationalError, ProgrammingError):
|
||||||
setting = None
|
setting = None
|
||||||
|
|
||||||
# Setting does not exist! (Try to create it)
|
# Setting does not exist! (Try to create it)
|
||||||
@ -512,7 +512,7 @@ class BaseInvenTreeSetting(models.Model):
|
|||||||
# Wrap this statement in "atomic", so it can be rolled back if it fails
|
# Wrap this statement in "atomic", so it can be rolled back if it fails
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
setting.save(**kwargs)
|
setting.save(**kwargs)
|
||||||
except (IntegrityError, OperationalError):
|
except (IntegrityError, OperationalError, ProgrammingError):
|
||||||
# It might be the case that the database isn't created yet
|
# It might be the case that the database isn't created yet
|
||||||
pass
|
pass
|
||||||
except ValidationError:
|
except ValidationError:
|
||||||
|
@ -182,8 +182,11 @@ class LabelConfig(AppConfig):
|
|||||||
shutil.copyfile(src_file, dst_file)
|
shutil.copyfile(src_file, dst_file)
|
||||||
|
|
||||||
# Check if a label matching the template already exists
|
# Check if a label matching the template already exists
|
||||||
if model.objects.filter(label=filename).exists():
|
try:
|
||||||
return # pragma: no cover
|
if model.objects.filter(label=filename).exists():
|
||||||
|
return # pragma: no cover
|
||||||
|
except Exception:
|
||||||
|
logger.error(f"Failed to query label for '{filename}' - you should run 'invoke update' first!")
|
||||||
|
|
||||||
logger.info(f"Creating entry for {model} '{label['name']}'")
|
logger.info(f"Creating entry for {model} '{label['name']}'")
|
||||||
|
|
||||||
|
@ -55,12 +55,15 @@ class PartConfig(AppConfig):
|
|||||||
if isImportingData():
|
if isImportingData():
|
||||||
return
|
return
|
||||||
|
|
||||||
items = PartPricing.objects.filter(scheduled_for_update=True)
|
try:
|
||||||
|
items = PartPricing.objects.filter(scheduled_for_update=True)
|
||||||
|
|
||||||
if items.count() > 0:
|
if items.count() > 0:
|
||||||
# Find any pricing objects which have the 'scheduled_for_update' flag set
|
# Find any pricing objects which have the 'scheduled_for_update' flag set
|
||||||
print(f"Resetting update flags for {items.count()} pricing objects...")
|
logger.info(f"Resetting update flags for {items.count()} pricing objects...")
|
||||||
|
|
||||||
for pricing in items:
|
for pricing in items:
|
||||||
pricing.scheduled_for_update = False
|
pricing.scheduled_for_update = False
|
||||||
pricing.save()
|
pricing.save()
|
||||||
|
except Exception:
|
||||||
|
logger.error("Failed to reset pricing flags - database not ready")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user