Fixed weird bug with versatile imgae field

This commit is contained in:
Eliot Berriot 2018-07-21 11:57:37 +02:00
parent 24132fa1a3
commit 886680ed15
No known key found for this signature in database
GPG Key ID: DD6965E2476E5C27
1 changed files with 7 additions and 0 deletions

View File

@ -107,6 +107,13 @@ class PlaylistSerializer(serializers.ModelSerializer):
covers = []
max_covers = 5
for plt in plts:
if not hasattr(plt.track.album.cover, "crop"):
# In some rare situations, we end up with the following stack strace:
# AttributeError: 'VersatileImageFieldFile' object has no attribute 'crop'
# I tend to thing our complex prefetch logic is troubling for versatile
# image field, so wi initialize the missing attribute by hand, cf
# https://github.com/respondcreate/django-versatileimagefield/blob/1.9/versatileimagefield/mixins.py#L108
plt.track.album.cover.build_filters_and_sizers((0.5, 0, 5), False)
url = plt.track.album.cover.crop["200x200"].url
if url in covers:
continue