2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 03:00:54 +00:00

Error tweaks (#9891)

* Wrap model import in try/except

* Fix circular imports

* Adjust exception handling
This commit is contained in:
Oliver
2025-06-28 10:25:24 +10:00
committed by GitHub
parent ff6d4bfb8f
commit 4b70a6e4ca
2 changed files with 16 additions and 5 deletions

View File

@ -38,7 +38,15 @@ def log_error(
scope: The scope of the error (optional)
plugin: The plugin name associated with this error (optional)
"""
from error_report.models import Error
import InvenTree.ready
if any([
InvenTree.ready.isImportingData(),
InvenTree.ready.isRunningMigrations(),
InvenTree.ready.isRunningBackup(),
]):
logger.exception('Exception occurred during import, migration, or backup')
return
if not path:
path = ''
@ -78,6 +86,8 @@ def log_error(
kind = kind[:128]
try:
from error_report.models import Error
Error.objects.create(kind=kind, info=info or '', data=data or '', path=path)
except Exception:
# Not much we can do if logging the error throws a db exception

View File

@ -15,15 +15,12 @@ from djmoney.money import Money
import common.currency
import common.models
import InvenTree.helpers
import part.models
import stock.models
logger = structlog.get_logger('inventree')
def perform_stocktake(
target: part.models.Part, user: User, note: str = '', commit=True, **kwargs
):
def perform_stocktake(target, user: User, note: str = '', commit=True, **kwargs):
"""Perform stocktake action on a single part.
Arguments:
@ -44,6 +41,8 @@ def perform_stocktake(
In this case, the stocktake *report* will be limited to the specified location.
"""
import part.models
# Determine which locations are "valid" for the generated report
location = kwargs.get('location')
locations = location.get_descendants(include_self=True) if location else []
@ -162,6 +161,8 @@ def generate_stocktake_report(**kwargs):
generate_report: If True, generate a stocktake report from the calculated data (default=True)
update_parts: If True, save stocktake information against each filtered Part (default = True)
"""
import part.models
# Determine if external locations should be excluded
exclude_external = kwargs.get(
'exclude_exernal',