subsonic: Don't crash when serialising artist with no name
If the name of an artist is not set, the serialiser will crash. Instead, just skip such an artist when serialising a list of artists. Also add test for serialising an artist with an empty name. Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
This commit is contained in:
parent
2f46d83834
commit
8193782f68
|
@ -24,7 +24,8 @@ class GetArtistsSerializer(serializers.Serializer):
|
|||
|
||||
first_letter_mapping = collections.defaultdict(list)
|
||||
for artist in values:
|
||||
first_letter_mapping[artist["name"][0].upper()].append(artist)
|
||||
if artist["name"]:
|
||||
first_letter_mapping[artist["name"][0].upper()].append(artist)
|
||||
|
||||
for letter, artists in sorted(first_letter_mapping.items()):
|
||||
letter_data = {
|
||||
|
|
|
@ -6,6 +6,7 @@ def test_get_artists_serializer(factories):
|
|||
artist1 = factories["music.Artist"](name="eliot")
|
||||
artist2 = factories["music.Artist"](name="Ellena")
|
||||
artist3 = factories["music.Artist"](name="Rilay")
|
||||
artist4 = factories["music.Artist"](name="") # Shouldn't be serialised
|
||||
|
||||
factories["music.Album"].create_batch(size=3, artist=artist1)
|
||||
factories["music.Album"].create_batch(size=2, artist=artist2)
|
||||
|
@ -28,7 +29,7 @@ def test_get_artists_serializer(factories):
|
|||
}
|
||||
|
||||
queryset = artist1.__class__.objects.filter(
|
||||
pk__in=[artist1.pk, artist2.pk, artist3.pk]
|
||||
pk__in=[artist1.pk, artist2.pk, artist3.pk, artist4.pk]
|
||||
)
|
||||
|
||||
assert serializers.GetArtistsSerializer(queryset).data == expected
|
||||
|
|
Loading…
Reference in New Issue