Commit 7e79826b authored by Mickaël Desfrênes's avatar Mickaël Desfrênes
Browse files

Prevent crash when image size can't be found. Add log warning.

parent f8832a2c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
__version__ = "0.1.47"
__version__ = "0.1.48"
+13 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ from subprocess import call
from django.utils.timezone import now
from resources import tasks
import pytesseract
import logging
from PIL import Image, UnidentifiedImageError
from functools import cache
from django.db.models.query import QuerySet
@@ -19,6 +20,8 @@ Image.MAX_IMAGE_PIXELS = None

XLSX_MULTIPLE_VALUES_SEPARATOR = "\n--\n"

logger = logging.getLogger(__name__)


def _flatten_resource(
    resource: "Resource", known_metadatas: dict, metadatas_labels: List
@@ -342,8 +345,13 @@ class File(Resource):
                    except ValueError:
                        pass
            else:
                try:
                    image = Image.open(self.local_path())
                    val, _ = image.size
                except UnidentifiedImageError:
                    logger.warning(
                        f"Could not get width for file({self.pk}) using PIL. Possible image corruption."
                    )
        return val

    def image_height_from_metas(self) -> Union[int, None]:
@@ -360,8 +368,13 @@ class File(Resource):
                    except ValueError:
                        pass
            else:
                try:
                    image = Image.open(self.local_path())
                    _, val = image.size
                except UnidentifiedImageError:
                    logger.warning(
                        f"Could not get height for file({self.pk}) using PIL. Possible image corruption."
                    )
        return val

    class Meta: