2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 19:46:46 +00:00

Catch Part.DoesNotExist (#5092)

- Can be thrown when importing Part instances
- Fixes https://github.com/inventree/InvenTree/issues/5090
This commit is contained in:
Oliver 2023-06-23 21:30:51 +10:00 committed by GitHub
parent 198245d0d2
commit 603aef5da9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -455,6 +455,7 @@ class Part(InvenTreeBarcodeMixin, InvenTreeNotesMixin, MetadataMixin, MPTTModel)
"""
if self.pk:
try:
previous = Part.objects.get(pk=self.pk)
# Image has been changed
@ -466,6 +467,8 @@ class Part(InvenTreeBarcodeMixin, InvenTreeNotesMixin, MetadataMixin, MPTTModel)
if n_refs == 0:
logger.info(f"Deleting unused image file '{previous.image}'")
previous.image.delete(save=False)
except Part.DoesNotExist:
pass
self.full_clean()