Skip to content

Fix album duplicate detection using MusicBrainz IDs - #7027

Closed
gbcox wants to merge 1 commit into
beetbox:masterfrom
gbcox:fix-import-duplicate-mbids
Closed

gbcox wants to merge 1 commit into
beetbox:masterfrom
gbcox:fix-import-duplicate-mbids

Conversation

@gbcox

@gbcox gbcox commented Sep 13, 2026

Copy link
Copy Markdown

Description

Fixes #7026.

Prevent album imports from treating distinct MusicBrainz releases as duplicates solely because their album artist and title match.

Duplicate candidates now compare MusicBrainz identifiers in order of specificity:

  1. When both albums have release IDs, those IDs determine whether the candidate is retained.
  2. Otherwise, when both albums have release-group IDs, those IDs determine whether the candidate is retained.
  3. When comparable identifiers are unavailable, duplicate detection falls back to the configured duplicate_keys behavior.

Release IDs take precedence over release-group IDs. This permits multiple pressings, remasters, regional editions, or deluxe editions from the same release group to coexist in a library.

As-is metadata aggregation now preserves mb_releasegroupid, allowing this logic to work with beet import -A.

Regression tests cover matching and conflicting release IDs, matching and conflicting release-group IDs, different releases within the same release group, and fallback behavior when comparable identifiers are unavailable.

The packaged fix was also tested through COPR against the original real-world cases:

  • Santana’s distinct 1969 and 1971 self-titled albums were imported without a false duplicate prompt.
  • Weezer’s multiple self-titled albums were imported without false duplicate prompts.

Both manual tests used beet import -A against an existing library.

To Do

  • Documentation—not required because this fixes existing duplicate-detection behavior without changing the command-line interface.
  • Changelog.
  • Tests.

@gbcox
gbcox requested a review from a team as a code owner September 13, 2026 03:56
@github-actions github-actions Bot added the musicbrainz musicbrainz plugin label Sep 13, 2026

@semohr semohr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are trying to keep the plugin logic separate from core logic. Therefore, I think we should not add this logic here, at-least not in the current musicbrainz specific form.


Shouldn't it be possible to use the duplicate_keys configuration option for this?

@gbcox

gbcox commented Sep 13, 2026

Copy link
Copy Markdown
Author

You’re right. I overlooked that duplicate_keys can include mb_albumid and that an existing album must match all configured fields.

I downgraded to the unpatched beets package and tested both original reproductions after configuring:

duplicate_keys:
album: albumartist album mb_albumid
item: artist title

Both the Santana and Weezer directory imports completed without false duplicate prompts.

I focused too narrowly on the default albumartist album query and incorrectly treated it as fixed importer policy rather than a configurable choice. The omission of mb_releasegroupid from as-is album aggregation also led me in the wrong direction, but that field is not needed for this use case because mb_albumid is already preserved.

Thanks for pointing me to the intended mechanism. I’ll close this PR since the core change is unnecessary. This is exactly why code review is valuable. The existing configuration mechanism is a better solution than adding special-case logic to core.

@gbcox gbcox closed this Sep 13, 2026
@gbcox
gbcox deleted the fix-import-duplicate-mbids branch September 13, 2026 18:37
@semohr

semohr commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

No worries! Feel free to make an addition to the docs if it is not entirely clear!

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

Labels

musicbrainz musicbrainz plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False duplicate detection for distinct albums with identical artist and title

2 participants