diff --git a/api/funkwhale_api/music/tasks.py b/api/funkwhale_api/music/tasks.py index 946d7a411f9de1e1eb6089fd148974718e20ea65..e9c73273e4395da4b2419f0050b6dc20f50ebb54 100644 --- a/api/funkwhale_api/music/tasks.py +++ b/api/funkwhale_api/music/tasks.py @@ -431,9 +431,10 @@ def _get_track(data): artist_mbid = data.get("musicbrainz_artistid", None) artist_fid = data.get("artist_fid", None) artist_name = data["artist"] - query = Q(name__iexact=artist_name) if artist_mbid: - query |= Q(mbid=artist_mbid) + query = Q(mbid=artist_mbid) + else: + query = Q(name__iexact=artist_name) if artist_fid: query |= Q(fid=artist_fid) defaults = { @@ -476,9 +477,12 @@ def _get_track(data): # get / create album album_title = data["album"] album_fid = data.get("album_fid", None) - query = Q(title__iexact=album_title, artist=album_artist) + if album_mbid: - query |= Q(mbid=album_mbid) + query = Q(mbid=album_mbid) + else: + query = Q(title__iexact=album_title, artist=album_artist) + if album_fid: query |= Q(fid=album_fid) defaults = { diff --git a/api/tests/music/test_tasks.py b/api/tests/music/test_tasks.py index ac62c31b86c3ebc7d893ac9b79361ab59792d516..76d820cca73f75d39f16fee3382ffdd2118fc193 100644 --- a/api/tests/music/test_tasks.py +++ b/api/tests/music/test_tasks.py @@ -133,6 +133,29 @@ def test_can_create_track_from_file_metadata_fid_existing_album_artist( assert track.artist == artist +def test_can_create_track_from_file_metadata_distinct_release_mbid(factories): + """Cf https://dev.funkwhale.audio/funkwhale/funkwhale/issues/772""" + artist = factories["music.Artist"]() + album = factories["music.Album"](artist=artist) + track = factories["music.Track"](album=album, artist=artist) + metadata = { + "artist": artist.name, + "album": album.title, + "title": track.title, + "track_number": 4, + "fid": "https://hello", + "musicbrainz_artistid": artist.mbid, + "musicbrainz_albumid": str(uuid.uuid4()), + } + + new_track = tasks.get_track_from_import_metadata(metadata) + + # the returned track should be different from the existing one, and mapped + # to a new album, because the albumid is different + assert new_track.album != album + assert new_track != track + + def test_can_create_track_from_file_metadata_federation(factories, mocker, r_mock): metadata = { "artist": "Artist", diff --git a/changes/changelog.d/772.bugfix b/changes/changelog.d/772.bugfix new file mode 100644 index 0000000000000000000000000000000000000000..5c0ddbeae0326003b432ac2fed62fc15c9994a47 --- /dev/null +++ b/changes/changelog.d/772.bugfix @@ -0,0 +1 @@ +Prevent skipping on file import if album_mbid is different (#772)