From 022182e1146a8c66abdcd6ec913da4b967f40e33 Mon Sep 17 00:00:00 2001 From: Joachim Date: Sat, 29 May 2021 11:33:37 +0200 Subject: [PATCH] See if the image is saved in DB in the Github Actions test environment --- bookwyrm/preview_images.py | 46 +++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/bookwyrm/preview_images.py b/bookwyrm/preview_images.py index 41dbf8bc7..0d9f26e7d 100644 --- a/bookwyrm/preview_images.py +++ b/bookwyrm/preview_images.py @@ -309,33 +309,33 @@ def save_and_cleanup(image, instance=None): file_name = "%s-%s.jpg" % (str(instance.id), str(uuid4())) image_buffer = BytesIO() + # try: try: - try: - old_path = instance.preview_image.path - except ValueError: - old_path = "" + old_path = instance.preview_image.path + except ValueError: + old_path = "" - # Save - image.save(image_buffer, format="jpeg", quality=75) - instance.preview_image = InMemoryUploadedFile( - ContentFile(image_buffer.getvalue()), - "preview_image", - file_name, - "image/jpg", - image_buffer.tell(), - None, - ) + # Save + image.save(image_buffer, format="jpeg", quality=75) + instance.preview_image = InMemoryUploadedFile( + ContentFile(image_buffer.getvalue()), + "preview_image", + file_name, + "image/jpg", + image_buffer.tell(), + None, + ) - save_without_broadcast = isinstance(instance, (models.Book, models.User)) - if save_without_broadcast: - instance.save(update_fields=["preview_image"], broadcast=False) - else: - instance.save(update_fields=["preview_image"]) + save_without_broadcast = isinstance(instance, (models.Book, models.User)) + if save_without_broadcast: + instance.save(update_fields=["preview_image"], broadcast=False) + else: + instance.save(update_fields=["preview_image"]) - # Clean up old file after saving - if os.path.exists(old_path): - os.remove(old_path) - finally: + # Clean up old file after saving + if os.path.exists(old_path): + os.remove(old_path) + # finally: image_buffer.close()