fix: scan backfills release type metadata onto pre-existing rows
MonitoredRelease rows created before an artist's discography was populated (e.g. an owned album recorded before _populate_discography ran) never got primaryType/secondaryTypes backfilled, wrongly excluding them from the studio-only core view. _populate_discography now DO UPDATEs the MB type metadata on conflict instead of DO NOTHING, leaving monitored/state/currentQualityClass/firstGrabbedAt untouched. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -142,3 +142,29 @@ def test_scan_populates_full_discography_unmonitored(conn, tmp_path):
|
||||
assert cur.fetchone() == (True, "fulfilled") # owned album stays monitored+fulfilled
|
||||
cur.execute('SELECT monitored, state FROM "MonitoredRelease" WHERE "rgMbid"=%s', ("rg-other",))
|
||||
assert cur.fetchone() == (False, "wanted") # the rest are unmonitored
|
||||
|
||||
|
||||
def test_scan_backfills_type_on_preexisting_typeless_owned_row(conn, tmp_path):
|
||||
from lyra_worker.adapters.fakes import FakeMbBrowser
|
||||
from lyra_worker.browser import ReleaseGroupInfo
|
||||
# simulate an owned row recorded by an older scan: monitored+fulfilled but NULL primaryType
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
'INSERT INTO "MonitoredRelease" (id, "artistMbid", "artistName", "rgMbid", album, '
|
||||
'"secondaryTypes", monitored, state, "currentQualityClass", "createdAt") '
|
||||
"VALUES (gen_random_uuid()::text, 'a50', '50 Cent', 'rg-owned', 'Get Rich or Die Tryin''', "
|
||||
"'{}', true, 'fulfilled', 2, now())"
|
||||
)
|
||||
conn.commit()
|
||||
_album(tmp_path, "50 Cent", "Get Rich or Die Tryin' (2003)")
|
||||
resolver = FakeResolver({
|
||||
("50 Cent", "Get Rich or Die Tryin'"): MBTarget(
|
||||
artist="50 Cent", album="Get Rich or Die Tryin'", year=2003, rg_mbid="rg-owned", artist_mbid="a50"),
|
||||
})
|
||||
browser = FakeMbBrowser(releases={"a50": [
|
||||
ReleaseGroupInfo("rg-owned", "Get Rich or Die Tryin'", "Album", (), "2003-02-06"),
|
||||
]})
|
||||
scan_library(conn, resolver, FakeProbe(quality_class=2), browser, dest_root=str(tmp_path))
|
||||
with conn.cursor() as cur:
|
||||
cur.execute('SELECT "primaryType", monitored, state, "currentQualityClass" FROM "MonitoredRelease" WHERE "rgMbid"=%s', ("rg-owned",))
|
||||
assert cur.fetchone() == ("Album", True, "fulfilled", 2) # type backfilled, state preserved
|
||||
|
||||
Reference in New Issue
Block a user