Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
fabienheureux committed Jan 22, 2022
1 parent e6f6e41 commit 82c677b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion wagtail_wordpress_import/block_builder_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.core.files import File
from django.core.files.temp import NamedTemporaryFile
from django.utils.module_loading import import_string
from django.db.utils import IntegrityError
from wagtail.documents import get_document_model
from wagtail.images import get_image_model

Expand Down Expand Up @@ -128,7 +129,10 @@ def get_or_save_image(src):
retrieved_image = ImportedImage(
file=File(file=temp_image), title=image_file_name
)
retrieved_image.save()
try:
retrieved_image.save()
except IntegrityError:
retrieved_image = None
temp_image.close()
return retrieved_image
else:
Expand Down

0 comments on commit 82c677b

Please sign in to comment.