Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix KeyError: storageFilename by deleting mediaItems from collection if unable to download image #36

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions app/lib/store_images_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down