From 85ef42c1cd239df2e9087c3c404441e425cb160b Mon Sep 17 00:00:00 2001 From: Mack Talcott Date: Mon, 15 Jan 2024 16:22:12 -0800 Subject: [PATCH] Address missing storageFilename by deleting mediaItems from collection if unable to download image --- app/lib/store_images_task.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/lib/store_images_task.py b/app/lib/store_images_task.py index 7350cce..2ef5c61 100644 --- a/app/lib/store_images_task.py +++ b/app/lib/store_images_task.py @@ -36,8 +36,22 @@ def run(self): for media_item_id in self.media_item_ids: media_item = media_item_id_map[media_item_id] - storage_filename = self.image_store.store_image(media_item) - self.repo.update(media_item_id, {"storageFilename": storage_filename}) + try: + storage_filename = self.image_store.store_image(media_item) + self.repo.update(media_item_id, {"storageFilename": storage_filename}) + except Exception as error: + # Displaying and processing mediaItems requires we have an actual + # image file to work with (referenced by storageFilename). If + # we are unable to obtain an image for a particular mediaItem, + # we'll delete the mediaItem from the collection (rather than + # adding logic to handle this case everywhere else). + # See https://github.com/mtalcott/google-photos-deduper/issues/23 + logging.error( + f"Received {error} storing image, deleting mediaItem\n" + f"media_item: {media_item}\n" + ) + self.repo.delete([media_item_id]) + num_completed += 1 # Log every 3 seconds