From 3a1d180c3404acdb632f5993ffdb6b211ef3a81d Mon Sep 17 00:00:00 2001 From: Oliver Date: Sun, 1 Jan 2023 00:51:07 +1100 Subject: [PATCH] Catch potential issues when importing data (#4130) (cherry picked from commit aa7fb9729217cf21b50e0dd870826da33e3bc9a9) --- InvenTree/part/models.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 72e6e0e8de..210e0a46f0 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -2248,13 +2248,19 @@ class Part(InvenTreeBarcodeMixin, MetadataMixin, MPTTModel): @receiver(post_save, sender=Part, dispatch_uid='part_post_save_log') def after_save_part(sender, instance: Part, created, **kwargs): """Function to be executed after a Part is saved.""" + from pickle import PicklingError + from part import tasks as part_tasks - if not created and not InvenTree.ready.isImportingData(): + if instance and not created and not InvenTree.ready.isImportingData(): # Check part stock only if we are *updating* the part (not creating it) # Run this check in the background - InvenTree.tasks.offload_task(part_tasks.notify_low_stock_if_required, instance) + try: + InvenTree.tasks.offload_task(part_tasks.notify_low_stock_if_required, instance) + except PicklingError: + # Can sometimes occur if the referenced Part has issues + pass class PartPricing(models.Model):