From 73e7211398bffc362cb26e172c9eb350293fde21 Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Wed, 27 Nov 2019 15:56:56 +0100 Subject: [PATCH] Fix album cover migration crash with cover not found on disk --- .../music/migrations/0043_album_cover_attachment.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/api/funkwhale_api/music/migrations/0043_album_cover_attachment.py b/api/funkwhale_api/music/migrations/0043_album_cover_attachment.py index f5da4072a..17eda6b72 100644 --- a/api/funkwhale_api/music/migrations/0043_album_cover_attachment.py +++ b/api/funkwhale_api/music/migrations/0043_album_cover_attachment.py @@ -15,11 +15,14 @@ def create_attachments(apps, schema_editor): return "image/jpeg" for album in Album.objects.filter(attachment_cover=None).exclude(cover="").exclude(cover=None): - album_attachment_mapping[album] = Attachment( - file=album.cover, - size=album.cover.size, - mimetype=get_mimetype(album.cover.path), - ) + try: + album_attachment_mapping[album] = Attachment( + file=album.cover, + size=album.cover.size, + mimetype=get_mimetype(album.cover.path), + ) + except FileNotFoundError: + print('Skipping missing cover file {}'.format(album.cover.path)) Attachment.objects.bulk_create(album_attachment_mapping.values(), batch_size=2000) # map each attachment to the corresponding album