Skip to content

Commit

Permalink
Catch potential issues when importing data (#4130)
Browse files Browse the repository at this point in the history
(cherry picked from commit aa7fb97)
  • Loading branch information
SchrodingersGat authored Dec 31, 2022
1 parent c621c47 commit 3a1d180
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions InvenTree/part/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2248,13 +2248,19 @@ def is_part_low_on_stock(self):
@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):
Expand Down

0 comments on commit 3a1d180

Please sign in to comment.