mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 19:46:46 +00:00
Log plugin event errors (#6455)
* Log plugin event errors - Log errors from plugins running process_event function * Catch exception on custom validation * Catch some more errors * Fix circular imports
This commit is contained in:
parent
af4d888b1b
commit
325841dbf1
@ -97,6 +97,14 @@ class PluginValidationMixin(DiffMixin):
|
|||||||
return
|
return
|
||||||
except ValidationError as exc:
|
except ValidationError as exc:
|
||||||
raise exc
|
raise exc
|
||||||
|
except Exception as exc:
|
||||||
|
# Log the exception to the database
|
||||||
|
import InvenTree.exceptions
|
||||||
|
|
||||||
|
InvenTree.exceptions.log_error(
|
||||||
|
f'plugins.{plugin.slug}.validate_model_instance'
|
||||||
|
)
|
||||||
|
raise ValidationError(_('Error running plugin validation'))
|
||||||
|
|
||||||
def full_clean(self):
|
def full_clean(self):
|
||||||
"""Run plugin validation on full model clean.
|
"""Run plugin validation on full model clean.
|
||||||
|
@ -7,6 +7,7 @@ from django.db import transaction
|
|||||||
from django.db.models.signals import post_delete, post_save
|
from django.db.models.signals import post_delete, post_save
|
||||||
from django.dispatch.dispatcher import receiver
|
from django.dispatch.dispatcher import receiver
|
||||||
|
|
||||||
|
import InvenTree.exceptions
|
||||||
from InvenTree.ready import canAppAccessDatabase, isImportingData
|
from InvenTree.ready import canAppAccessDatabase, isImportingData
|
||||||
from InvenTree.tasks import offload_task
|
from InvenTree.tasks import offload_task
|
||||||
from plugin.registry import registry
|
from plugin.registry import registry
|
||||||
@ -95,9 +96,16 @@ def process_event(plugin_slug, event, *args, **kwargs):
|
|||||||
logger.error("Could not find matching plugin for '%s'", plugin_slug)
|
logger.error("Could not find matching plugin for '%s'", plugin_slug)
|
||||||
return
|
return
|
||||||
|
|
||||||
plugin.process_event(event, *args, **kwargs)
|
|
||||||
logger.debug("Plugin '%s' is processing triggered event '%s'", plugin_slug, event)
|
logger.debug("Plugin '%s' is processing triggered event '%s'", plugin_slug, event)
|
||||||
|
|
||||||
|
try:
|
||||||
|
plugin.process_event(event, *args, **kwargs)
|
||||||
|
except Exception as e:
|
||||||
|
# Log the exception to the database
|
||||||
|
InvenTree.exceptions.log_error(f'plugins.{plugin_slug}.process_event')
|
||||||
|
# Re-throw the exception so that the background worker tries again
|
||||||
|
raise Exception
|
||||||
|
|
||||||
|
|
||||||
def allow_table_event(table_name):
|
def allow_table_event(table_name):
|
||||||
"""Determine if an automatic event should be fired for a given table.
|
"""Determine if an automatic event should be fired for a given table.
|
||||||
|
@ -16,6 +16,7 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
|
|
||||||
import build.models
|
import build.models
|
||||||
import common.models
|
import common.models
|
||||||
|
import InvenTree.exceptions
|
||||||
import InvenTree.models
|
import InvenTree.models
|
||||||
import order.models
|
import order.models
|
||||||
import part.models
|
import part.models
|
||||||
@ -263,7 +264,12 @@ class ReportTemplateBase(MetadataMixin, ReportBase):
|
|||||||
|
|
||||||
for plugin in plugins:
|
for plugin in plugins:
|
||||||
# Let each plugin add its own context data
|
# Let each plugin add its own context data
|
||||||
plugin.add_report_context(self, self.object_to_print, request, context)
|
try:
|
||||||
|
plugin.add_report_context(self, self.object_to_print, request, context)
|
||||||
|
except Exception:
|
||||||
|
InvenTree.exceptions.log_error(
|
||||||
|
f'plugins.{plugin.slug}.add_report_context'
|
||||||
|
)
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ from mptt.models import MPTTModel, TreeForeignKey
|
|||||||
from taggit.managers import TaggableManager
|
from taggit.managers import TaggableManager
|
||||||
|
|
||||||
import common.models
|
import common.models
|
||||||
|
import InvenTree.exceptions
|
||||||
import InvenTree.helpers
|
import InvenTree.helpers
|
||||||
import InvenTree.models
|
import InvenTree.models
|
||||||
import InvenTree.ready
|
import InvenTree.ready
|
||||||
@ -601,6 +602,10 @@ class StockItem(
|
|||||||
plugin.validate_batch_code(self.batch, self)
|
plugin.validate_batch_code(self.batch, self)
|
||||||
except ValidationError as exc:
|
except ValidationError as exc:
|
||||||
raise ValidationError({'batch': exc.message})
|
raise ValidationError({'batch': exc.message})
|
||||||
|
except Exception:
|
||||||
|
InvenTree.exceptions.log_error(
|
||||||
|
f'plugin.{plugin.slug}.validate_batch_code'
|
||||||
|
)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
"""Validate the StockItem object (separate to field validation).
|
"""Validate the StockItem object (separate to field validation).
|
||||||
|
Loading…
x
Reference in New Issue
Block a user