diff --git a/api/funkwhale_api/subsonic/views.py b/api/funkwhale_api/subsonic/views.py index bb5f44166875f34ee7b625c60d93dd004d9bc6a0..de7284cd62cd502edf5d0aacb7abf785a23e7479 100644 --- a/api/funkwhale_api/subsonic/views.py +++ b/api/funkwhale_api/subsonic/views.py @@ -38,7 +38,7 @@ def find_object(queryset, model_field="pk", field="id", cast=int): ) try: value = cast(raw_value) - except (TypeError, ValidationError): + except (ValueError, TypeError, ValidationError): return response.Response( { "error": { diff --git a/api/tests/subsonic/test_views.py b/api/tests/subsonic/test_views.py index b7431efab4a05962fa6ed5d34ba0c963336ad9a3..d9b50d3eb25ac574364eeaaa37e57e8c22685691 100644 --- a/api/tests/subsonic/test_views.py +++ b/api/tests/subsonic/test_views.py @@ -102,6 +102,17 @@ def test_get_artist(f, db, logged_in_api_client, factories): assert response.data == expected +@pytest.mark.parametrize("f", ["xml", "json"]) +def test_get_invalid_artist(f, db, logged_in_api_client, factories): + url = reverse("api:subsonic-get-artist") + assert url.endswith("getArtist") is True + expected = {"error": {"code": 0, "message": 'For input string "asdf"'}} + response = logged_in_api_client.get(url, {"id": "asdf"}) + + assert response.status_code == 200 + assert response.data == expected + + @pytest.mark.parametrize("f", ["xml", "json"]) def test_get_artist_info2(f, db, logged_in_api_client, factories): url = reverse("api:subsonic-get-artist-info2")