Fix album cover migration crash with cover not found on disk

This commit is contained in:
Eliot Berriot 2019-11-27 15:56:56 +01:00
parent 0aa03af34d
commit 73e7211398
No known key found for this signature in database
GPG Key ID: 6B501DFD73514E14
1 changed files with 8 additions and 5 deletions

View File

@ -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