fix: index albums through the endpoint Lidarr does not throw from
Build and publish container / build (pull_request) Successful in 8m1s
Build and publish container / build (pull_request) Successful in 8m1s
Indexing fetched albums one artist at a time, and `GET /api/v1/album?artistId=` is Lidarr's unguarded path. It maps straight from the album service with no hydration: the mapper then dereferences model.Images and model.SecondaryTypes without a null check, follows model.Artist?.Value where only the first link is guarded, and selects the monitored release with SingleOrDefault, which throws outright when an album has two of them. Any of those is a 500 that aborts the whole index. The unfiltered `GET /api/v1/album` builds its own artist and release lookups and skips an album whose metadata is missing rather than dereferencing it. Use that instead, once, and group by artistId locally. It is the defensive path and it costs N fewer requests. Tracks and files have no unfiltered endpoint -- Lidarr rejects a call with no filter at all -- so those stay per artist. A failure on one artist now skips that artist rather than ending the run, but the count is recorded in the store and the coverage report leads with it: a missing artist makes their played music look unplayed, which is precisely the error that costs music later, so an incomplete index must not be culled against. Errors now carry the request URL and whatever the server put in the body. The original report of this failure was "album: HTTP 500", which points at the URL and the credentials -- neither of which was at fault.
This commit is contained in:
@@ -500,3 +500,61 @@ def test_matching_is_redone_when_new_scrobbles_arrive(tmp_path):
|
||||
music_curator.run_once(client_for(api), store, "lyra", NOW, 0)
|
||||
|
||||
assert verdict(store, "Yellowcard", "Transmission Home")[0] == "name"
|
||||
|
||||
|
||||
def test_albums_come_from_the_unfiltered_endpoint(tmp_path):
|
||||
"""`?artistId=` is Lidarr's unguarded path and 500s on data it cannot
|
||||
hydrate; the unfiltered one skips such albums instead."""
|
||||
api = FakeLidarr(LIBRARY)
|
||||
store = store_at(tmp_path)
|
||||
|
||||
music_curator.index_library(music_curator.Lidarr("http://lidarr", "key", transport=api), store)
|
||||
|
||||
album_calls = [query for path, query in api.calls if path == "album"]
|
||||
assert album_calls == [{}]
|
||||
assert store.scalar("SELECT COUNT(*) FROM lidarr_album") == 3
|
||||
|
||||
|
||||
def test_an_artist_lidarr_cannot_serve_does_not_kill_the_index(tmp_path):
|
||||
# Artist 2 is AC/DC in LIBRARY; its track lookup fails.
|
||||
api = FakeLidarr(LIBRARY, fail=[("track", 2)])
|
||||
store = store_at(tmp_path)
|
||||
|
||||
music_curator.index_library(music_curator.Lidarr("http://lidarr", "key", transport=api), store)
|
||||
|
||||
assert store.scalar("SELECT COUNT(*) FROM lidarr_artist") == 3
|
||||
assert store.scalar("SELECT COUNT(*) FROM lidarr_track WHERE artist_id = 2") == 0
|
||||
# The other two artists are indexed in full.
|
||||
assert store.scalar("SELECT COUNT(*) FROM lidarr_track") == 3
|
||||
assert store.get_state("index_skipped") == "1"
|
||||
|
||||
|
||||
def test_a_skipped_artist_is_recorded_so_the_report_can_disown_the_numbers(tmp_path):
|
||||
"""An incomplete index makes played music look cold. It has to be loud."""
|
||||
api = FakeLidarr(LIBRARY, fail=[("trackfile", 1)])
|
||||
store = store_at(tmp_path)
|
||||
|
||||
music_curator.index_library(music_curator.Lidarr("http://lidarr", "key", transport=api), store)
|
||||
music_curator.match_library(store)
|
||||
|
||||
assert store.get_state("index_skipped") == "1"
|
||||
|
||||
|
||||
def test_a_clean_index_records_no_skips(tmp_path):
|
||||
store = indexed(tmp_path, [])
|
||||
|
||||
assert store.get_state("index_skipped") == "0"
|
||||
|
||||
|
||||
def test_a_lidarr_error_carries_the_url_and_what_the_server_said():
|
||||
"""A bare status code sends you looking at the wrong thing entirely."""
|
||||
api = FakeLidarr(LIBRARY, fail=[("album", 0)])
|
||||
client = music_curator.Lidarr("http://lidarr:8686", "key", transport=api)
|
||||
|
||||
with pytest.raises(music_curator.LidarrError) as raised:
|
||||
client.get("album")
|
||||
|
||||
message = str(raised.value)
|
||||
assert "http://lidarr:8686/api/v1/album" in message
|
||||
assert "HTTP 500" in message
|
||||
assert "boom" in message
|
||||
|
||||
Reference in New Issue
Block a user