diff --git a/core/artist_source_lookup.py b/core/artist_source_lookup.py index 32eac787..b965d4cf 100644 --- a/core/artist_source_lookup.py +++ b/core/artist_source_lookup.py @@ -43,7 +43,7 @@ def find_library_artist_for_source( database, source: str, source_artist_id: str, - artist_name: str, + artist_name: Optional[str] = None, active_server: Optional[str] = None, ) -> Optional[str]: """Return the library PK of an artist matching the source-aware click. diff --git a/tests/test_artist_source_lookup.py b/tests/test_artist_source_lookup.py index c33d864f..75ca4582 100644 --- a/tests/test_artist_source_lookup.py +++ b/tests/test_artist_source_lookup.py @@ -109,9 +109,7 @@ class TestFindLibraryArtistForSource: **{column: source_value}, ) - result = find_library_artist_for_source( - db, source, source_value, artist_name="" - ) + result = find_library_artist_for_source(db, source, source_value) assert result == f"pk-{source}" def test_unknown_source_returns_none(self, db): @@ -121,8 +119,16 @@ class TestFindLibraryArtistForSource: def test_lookup_misses_when_source_id_unknown(self, db): _insert_artist(db, artist_id="pk-real", name="Real Artist", deezer_id="dz-real") + assert find_library_artist_for_source(db, "deezer", "dz-not-real") is None + + def test_artist_name_is_optional(self, db): + """Callers that don't have a name handy should be able to omit it + without falling through to the name-fallback branch.""" + _insert_artist(db, artist_id="pk-q", name="Some Artist", server_source="plex") + # No source-id match, no name passed → must return None even when + # active_server is set (otherwise we'd risk matching by None name). assert find_library_artist_for_source( - db, "deezer", "dz-not-real", artist_name="" + db, "deezer", "no-id-match", active_server="plex" ) is None def test_name_fallback_matches_within_active_server(self, db): diff --git a/web_server.py b/web_server.py index d58f0fe8..a6302e66 100644 --- a/web_server.py +++ b/web_server.py @@ -11323,7 +11323,7 @@ from core.artist_source_lookup import ( ) -def _find_library_artist_for_source(database, source, source_artist_id, artist_name): +def _find_library_artist_for_source(database, source, source_artist_id, artist_name=None): """Thin wrapper that injects the active-server context for the core lookup.""" try: active_server = config_manager.get_active_media_server()