diff --git a/api/funkwhale_api/subsonic/views.py b/api/funkwhale_api/subsonic/views.py index e7c619a796096cdba1189eb13ecc14953df7b975..4f743abc3285fbd3f6c19e06f5c08e546f31fd0a 100644 --- a/api/funkwhale_api/subsonic/views.py +++ b/api/funkwhale_api/subsonic/views.py @@ -458,9 +458,7 @@ class SubsonicViewSet(viewsets.GenericViewSet): elif type == "alphabeticalByName" or not type: queryset = queryset.order_by("artist__title") elif type == "recent" or not type: - queryset = queryset.exclude(release_date__in=["", None]).order_by( - "-release_date" - ) + queryset = queryset.exclude(release_date=None).order_by("-release_date") elif type == "newest" or not type: queryset = queryset.order_by("-creation_date") elif type == "byGenre" and data.get("genre"): diff --git a/api/tests/subsonic/test_views.py b/api/tests/subsonic/test_views.py index 3c9bae5f1919c5288663da746a9e1a352bffa33c..d8bc5aeebbc25afef1d28035de2dec1e2b2ced70 100644 --- a/api/tests/subsonic/test_views.py +++ b/api/tests/subsonic/test_views.py @@ -435,6 +435,21 @@ def test_get_album_list2( playable_by.assert_called_once() +def test_get_album_list2_recent(db, logged_in_api_client, factories): + url = reverse("api:subsonic-get_album_list2") + assert url.endswith("getAlbumList2") is True + factories["music.Album"](playable=True, release_date=None) + album2 = factories["music.Album"](playable=True) + album3 = factories["music.Album"](playable=True) + response = logged_in_api_client.get(url, {"f": "json", "type": "recent"}) + + assert response.status_code == 200 + expected_albums = reversed(sorted([album3, album2], key=lambda a: a.release_date)) + assert response.data == { + "albumList2": {"album": serializers.get_album_list2_data(expected_albums)} + } + + @pytest.mark.parametrize("f", ["json"]) def test_get_album_list2_pagination(f, db, logged_in_api_client, factories): url = reverse("api:subsonic-get_album_list2") diff --git a/changes/changelog.d/1158.bugfix b/changes/changelog.d/1158.bugfix new file mode 100644 index 0000000000000000000000000000000000000000..ff7fdd40741e1d23ce840bd26f0133b75872bcd6 --- /dev/null +++ b/changes/changelog.d/1158.bugfix @@ -0,0 +1 @@ +Fixed crash when loading recent albums via Subsonic (#1158)