Skip to content

Fix recently listened widget and simple artist serializer

Ciarán Ainsworth requested to merge 1446-fix-recently-listened into develop

Closes #1446 (closed)

Looking at the above issue, I can see two problems:

  1. The Vue template is only looking for an album cover
  2. Channels such as podcasts with no series will have their cover art in one of two places: attached to the track or attached to the artist

The first of these is easily resolved. We can add v-else-if directives to grab other covers when no album art is available. This works for track covers, which are returned by the track serializer with no issues. However, the listenings endpoint returns no artist covers. I've tracked this down to the serialize_artist_simple serializer, which contains the following:

def serialize_artist_simple(artist):
    data = {
        "id": artist.id,
        "fid": artist.fid,
        "mbid": str(artist.mbid),
        "name": artist.name,
        "creation_date": DATETIME_FIELD.to_representation(artist.creation_date),
        "modification_date": DATETIME_FIELD.to_representation(artist.modification_date),
        "is_local": artist.is_local,
        "content_category": artist.content_category,
    }
    if "description" in artist._state.fields_cache:
        data["description"] = (
            common_serializers.ContentSerializer(artist.description).data
            if artist.description
            else None
        )

    if "attachment_cover" in artist._state.fields_cache:
        data["cover"] = (
            cover_field.to_representation(artist.attachment_cover)
            if artist.attachment_cover
            else None
        )
    if "channel" in artist._state.fields_cache and artist.get_channel():
        data["channel"] = str(artist.channel.uuid)

    if getattr(artist, "_tracks_count", None) is not None:
        data["tracks_count"] = artist._tracks_count

    if getattr(artist, "_prefetched_tagged_items", None) is not None:
        data["tags"] = [ti.tag.name for ti in artist._prefetched_tagged_items]

    return data

From my testing, none of the attributes that are checking the _state.fields_cache are returning any information. If we remove this check, the information is coming back as expected.

This check is only used in two places, but I don't really understand when, where, or how this fields_cache is set. Looking through Django's docs has not been particularly helpful.

Edited by Ciarán Ainsworth

Merge request reports