From 0e1d84733e569f9c62ce93cd82fc28ada80d9cc9 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Fri, 24 Mar 2023 10:52:23 +0100 Subject: [PATCH] Handle empty shortpixel --- src/attachments/models.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/attachments/models.py b/src/attachments/models.py index 7a48b02..2ea9813 100644 --- a/src/attachments/models.py +++ b/src/attachments/models.py @@ -1,6 +1,7 @@ from __future__ import annotations import json +import logging import tempfile from pathlib import Path from typing import Any @@ -16,6 +17,8 @@ from PIL import Image from articles.utils import build_full_absolute_url +logger = logging.getLogger(__name__) + class AbsoluteUrlFieldFile(FieldFile): def get_full_absolute_url(self, request: WSGIRequest) -> str: @@ -95,7 +98,12 @@ class Attachment(models.Model): files={self.original_file.name: original_file}, timeout=10, ) + res = response.json() + if len(res) == 0: + logger.error("Shortpixel response is empty: %s", res) + return super().save(*args, **kwargs) + res_data = res[0] # Loop until it's done