Fix duplicate_keys with mb_albumid/mb_trackid for autotagged imports by hippi345 · Pull Request #7078 · beetbox/beets · GitHub
Skip to content

Fix duplicate_keys with mb_albumid/mb_trackid for autotagged imports - #7078

Open
hippi345 wants to merge 3 commits into
beetbox:masterfrom
hippi345:cursor/fix-duplicate-keys-mbid-b29e
Open

hippi345 wants to merge 3 commits into
beetbox:masterfrom
hippi345:cursor/fix-duplicate-keys-mbid-b29e

Conversation

@hippi345

@hippi345 hippi345 commented Oct 5, 2026

Copy link
Copy Markdown

Fixes #7067

chosen_info() now uses match.info.item_data so library field names (mb_albumid/mb_trackid) are set for find_duplicates; albumartist override guarded for APPLY; changelog + album/singleton regression tests.

ImportTask.chosen_info() was returning self.match.info.copy() for APPLY
actions, which preserves raw AlbumInfo/TrackInfo field names (album_id,
track_id) instead of the library model names (mb_albumid, mb_trackid).
find_duplicates() then built a temporary Album/Item with mb_albumid
unset, causing the duplicate query to match library entries with an
empty MBID rather than the real duplicate.

Fix chosen_info() to return dict(self.match.info.item_data) for APPLY
actions. item_data applies MEDIA_FIELD_MAP which translates all
AlbumInfo/TrackInfo field names to their library equivalents, so
find_duplicates() now builds the temporary model with the correct
fields including mb_albumid and mb_trackid.

Also update ImportTask.find_duplicates() to handle the renamed artist
field: AlbumInfo.item_data maps 'artist' -> 'albumartist', so the
albumartist override is now guarded by a check for the 'artist' key
(present for ASIS/RETAG paths, absent for APPLY after item_data).

Add regression tests for both album (mb_albumid) and singleton
(mb_trackid) duplicate key paths.

Fixes beetbox#7067
@codecov

codecov Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

@hippi345
hippi345 marked this pull request as ready for review October 5, 2026 09:57
@hippi345
hippi345 requested a review from a team as a code owner October 5, 2026 09:57
When AlbumInfo.artist is None, item_data omits 'albumartist' entirely
(None values are filtered during item_data construction).  The guard
  if info.get("albumartist") is None: return []
was previously uncovered.  Add a focused unit test that constructs an
APPLY task with an artist-less AlbumMatch and asserts find_duplicates
returns [] immediately.
@hippi345
hippi345 marked this pull request as draft October 5, 2026 10:10
@hippi345
hippi345 marked this pull request as ready for review October 5, 2026 17:41

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

duplicate_keys: mb_albumid never matches on autotagged imports and matches albums without an MBID instead

1 participant