Skip to content

fix: duplicate album merge broken in threaded import mode - #6623

Merged
snejus merged 9 commits into
beetbox:masterfrom
arsaboo:import
May 17, 2026
Merged

fix: duplicate album merge broken in threaded import mode#6623
snejus merged 9 commits into
beetbox:masterfrom
arsaboo:import

Conversation

@arsaboo

@arsaboo arsaboo commented May 10, 2026

Copy link
Copy Markdown
Contributor

Fixes #6601

Added import contextvars and changed _extend_pipeline to capture the current context and run the inner pipeline within it to ensure the music_dir context variable is available when the inner pipeline resolves paths, preventing the relative-path bug that caused could not get filesize errors and removing 0 old duplicated items during merge.

Works perfectly after the fix:

arsaboo@arsmusic:~$ beet import -m -I -t ~/shared/music/ --set genre="Filmi" --search-id 7MwKD3kEFMov4LQqyhnmzL

/home/arsaboo/shared/music (1 items)

  Match (75.2%):
  King - Lukkhe
  ≠ artist, tracks
  Spotify, None, 2026, None, Warner Music India, None, None
  https://open.spotify.com/album/7MwKD3kEFMov4LQqyhnmzL
  ≠ Artist: King; OAFF; Savera; Sunny M.R. -> King
  * Album: Lukkhe
     ≠ (#2) Khamoshiyaan (3:03) -> (#2) Khamoshiyaan (feat. Romy & Manreet Khara) (3:03)
Missing tracks (13/14 - 92.9%):
 ! Bulletproof (#1) (3:09)
 ! Jee Lenge (#3) (3:25)
 ! Headshot (#4) (3:10)
 ! Ruh Teri (feat. Manreet Khara & Agrim Joshi) (#5) (2:31)
 ! Roobaroo (#6) (3:17)
 ! Savere (#7) (2:29)
 ! Haal (#8) (3:29)
 ! Haal (The Journey) (#9) (6:13)
 ! Nachdi Shaam (#10) (2:22)
 ! Hoga Bada Mera Naam (#11) (1:58)
 ! All Eyes On Us (#12) (3:13)
 ! Swan Song (Hoya Azaad) (#13) (3:17)
 ! Bhaari Pangey (#14) (2:19)
➜ [A]pply, More candidates, Skip, Use as-is, as Tracks, Group albums,
Enter search, enter Id, aBort, eDit, edit Candidates, Print tracks,
Open files with Picard? a
This album is already in the library!
Old: 3 items, MP3, 320kbps, 9:45, 22.9 MiB
New: 1 items, MP3, 320kbps, 3:03, 7.8 MiB
➜ [S]kip new, Keep all, Remove old, Merge all? m

/home/arsaboo/shared/music
/data/music/Hindi Music/L/Lukkhe [30718] (2026)/Lukkhe (2026) - Bulletproof.mp3
/data/music/Hindi Music/L/Lukkhe [30718] (2026)/Lukkhe (2026) - Headshot.mp3
/data/music/Hindi Music/L/Lukkhe [30718] (2026)/Lukkhe (2026) - Jee Lenge.mp3 (4 items)

  Match (82.6%):
  King - Lukkhe
  ≠ artist, tracks
  Spotify, None, 2026, None, Warner Music India, None, None
  https://open.spotify.com/album/7MwKD3kEFMov4LQqyhnmzL
  ≠ Artist: OAFF; Savera; Ruaa Kayy; Romy; Manreet Khara -> King
  * Album: Lukkhe
     * (#1) Bulletproof (3:09)
     ≠ (#2) Khamoshiyaan (3:03) -> (#2) Khamoshiyaan (feat. Romy & Manreet Khara) (3:03)
     * (#3) Jee Lenge (3:25)
     * (#4) Headshot (3:10)
Missing tracks (10/14 - 71.4%):
 ! Ruh Teri (feat. Manreet Khara & Agrim Joshi) (#5) (2:31)
 ! Roobaroo (#6) (3:17)
 ! Savere (#7) (2:29)
 ! Haal (#8) (3:29)
 ! Haal (The Journey) (#9) (6:13)
 ! Nachdi Shaam (#10) (2:22)
 ! Hoga Bada Mera Naam (#11) (1:58)
 ! All Eyes On Us (#12) (3:13)
 ! Swan Song (Hoya Azaad) (#13) (3:17)
 ! Bhaari Pangey (#14) (2:19)
➜ [A]pply, More candidates, Skip, Use as-is, as Tracks, Group albums,
Enter search, enter Id, aBort, eDit, edit Candidates, Print tracks,
Open files with Picard? a
  • Changelog. (Add an entry to docs/changelog.rst to the bottom of one of the lists near the top of the document.)
  • Tests. (Very much encouraged but not strictly required.)

@arsaboo
arsaboo requested a review from a team as a code owner May 10, 2026 14:35
Copilot AI review requested due to automatic review settings May 10, 2026 14:35
@arsaboo arsaboo changed the title Added import contextvars to capture the current context fix: duplicate album merge broken in threaded import mode May 10, 2026

Copilot AI 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.

Pull request overview

PR try fix bug #6601 where duplicate album MERGE in threaded import lose music_dir context, so db-relative paths stay relative and file ops fail.

Changes:

  • Add contextvars import in importer stages.
  • Change _extend_pipeline to snapshot current context and run inner pipeline inside it.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
docs/changelog.rst Add unreleased bug-fix note for threaded duplicate merge issue (#6601).
beets/importer/stages.py Capture current contextvars context around nested pipeline execution in _extend_pipeline.

Comment thread beets/importer/stages.py Outdated
Comment thread beets/importer/stages.py Outdated
@codecov

codecov Bot commented May 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.44%. Comparing base (44f7bf8) to head (6b760b7).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6623      +/-   ##
==========================================
+ Coverage   72.43%   72.44%   +0.01%     
==========================================
  Files         160      160              
  Lines       20681    20690       +9     
  Branches     3272     3272              
==========================================
+ Hits        14980    14989       +9     
  Misses       4976     4976              
  Partials      725      725              
Files with missing lines Coverage Δ
beets/importer/stages.py 88.75% <100.00%> (+0.63%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@semohr
semohr requested a review from snejus May 10, 2026 14:47

@snejus snejus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great. @arsaboo have you tested that it fixes the issue on your end?

@arsaboo

arsaboo commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

Yes, I'm using this branch and it works perfectly. Feel free to test it out.

Comment thread test/test_importer.py Outdated
Comment thread test/test_importer.py
Comment thread test/test_importer.py
Comment thread test/test_importer.py
"""Regression test for #6601: threaded merge must propagate context vars."""

plugin = "musicbrainz"
# Each thread gets its own connection; :memory: would give each thread an

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Love it!

@snejus
snejus merged commit aa33b1c into beetbox:master May 17, 2026
18 checks passed
@arsaboo
arsaboo deleted the import branch May 17, 2026 13:45
@skiinganchor

Copy link
Copy Markdown

@snejus when could we have a new release with this one?

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.

"Merge" option when dealing with duplicates does not work after 2.9.0 -> 2.10.0 upgrade

4 participants