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