Skip to content

fix(autotag): only write mb_* fields when data source is MusicBrainz#6507

Closed
aaronk6 wants to merge 1 commit intobeetbox:masterfrom
aaronk6:fix-mb-field-pollution
Closed

fix(autotag): only write mb_* fields when data source is MusicBrainz#6507
aaronk6 wants to merge 1 commit intobeetbox:masterfrom
aaronk6:fix-mb-field-pollution

Conversation

@aaronk6
Copy link
Copy Markdown
Contributor

@aaronk6 aaronk6 commented Apr 5, 2026

Description

Plugins like Spotify and Deezer set album_id, artist_id, and track_id on their AlbumInfo/TrackInfo objects, which apply_metadata() and apply_item_metadata() then unconditionally write to mb_albumid, mb_artistid, etc. This means service-specific IDs end up stored in MusicBrainz fields, breaking clients such as Music Assistant.

This PR adds a guard so that mb_* fields are only written when data_source == "MusicBrainz". Let me know if this is a good fix. If so, I’ll update the changelog and add some unit tests.

Note that a broader approach (registering Spotify/Deezer IDs as their own media fields) was explored in #6349, but it turned out to be quite complex, so this PR is just fixing the obvious problem.

To Do

  • Documentation.
  • Changelog.
  • Tests.

@aaronk6 aaronk6 requested a review from a team as a code owner April 5, 2026 21:43
Copilot AI review requested due to automatic review settings April 5, 2026 21:43
@github-actions github-actions Bot added the musicbrainz musicbrainz plugin label Apr 5, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 5, 2026

Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

PR make sure beets only write mb_* id fields when match data come from MusicBrainz, so Spotify/Deezer/etc ids no longer get stuffed into MusicBrainz slots and break downstream clients.

Changes:

  • Guard apply_item_metadata() so it only writes mb_trackid / mb_artistid(s) when track_info.data_source == "MusicBrainz".
  • Guard apply_metadata() so it only writes all mb_* ids when album_info.data_source == "MusicBrainz".

Comment thread beets/autotag/__init__.py
Comment thread beets/autotag/__init__.py Outdated
Comment on lines +202 to +208
if track_info.data_source == "MusicBrainz":
item.mb_trackid = track_info.track_id
item.mb_releasetrackid = track_info.release_track_id
if track_info.artist_id:
item.mb_artistid = track_info.artist_id
if track_info.artists_ids:
item.mb_artistids = track_info.artists_ids
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

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

grug want test. new behavior: when AlbumInfo/TrackInfo data_source not MusicBrainz (Spotify, Deezer), mb_* fields should not get service id. add regression test in test/autotag/test_autotag.py for apply_metadata + apply_item_metadata to prove mb_* stay empty/cleared.

Copilot generated this review using guidance from repository custom instructions.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I’ll add the test once I have maintainer feedback.

Comment thread beets/autotag/__init__.py Outdated
@aaronk6 aaronk6 force-pushed the fix-mb-field-pollution branch from dc21308 to 757ffaf Compare April 5, 2026 21:55
@snejus
Copy link
Copy Markdown
Member

snejus commented Apr 5, 2026

This will break beets for all items that are not from MusicBrainz. As I mentioned previously, these fields act as central ID storage mechanism for any data source. For example, see data source counts in my personal library:

7       youtube
8       spotify
12      Deezer
16      Spotify
201     soundcloud
395     MusicBrainz
1147    Discogs
7586    bandcamp

@snejus snejus closed this Apr 5, 2026
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.

3 participants