/
/
# What does this implement/fix? Merging two library items writes in steps and commits as it goes, so an interruption (a shutdown cancelling the hourly duplicate-track pass, for example) could stop the merge halfway. The source row then kept its provider mappings but had already lost its album and artist links — a track that still shows up in the library with no artist and no album, opens fine, and only fails when you try to play it. Nothing in the codebase could spot or repair that afterwards, because every pass that looks for duplicates needs exactly those links. The merge now copies the relations onto the target instead of moving them, and only drops the source's copies once the target holds both them and the provider mappings. Every point the merge can be cut short at is now one that an existing pass finishes on a later run. **Related issue (if applicable):** - n/a ## Types of changes - [ ] Bugfix (non-breaking change which fixes an issue) — `bugfix` - [ ] New feature (non-breaking change which adds functionality) — `new-feature` - [ ] Enhancement to an existing feature — `enhancement` - [ ] New music/player/metadata/plugin provider — `new-provider` - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) — `breaking-change` - [ ] Refactor (no behaviour change) — `refactor` - [ ] Documentation only — `documentation` - [x] Maintenance / chore — `maintenance` - [ ] CI / workflow change — `ci` - [ ] Dependencies bump — `dependencies` Changes: - Copy an item's album/artist relations onto the merge target rather than moving them, and drop the source's copies only after the provider mappings have moved - Clean up relation rows whose item no longer exists during the periodic database cleanup - Tests covering both points a merge can be interrupted at, and the new cleanup ## Checklist - [x] The code change is tested and works locally. - [x] `pre-commit run --all-files` passes. - [x] `pytest` passes, and tests have been added/updated under `tests/` where applicable. - [ ] For changes to shared models, the companion PR in `music-assistant/models` is linked. - [ ] For changes affecting the UI, the companion PR in `music-assistant/frontend` is linked. - [x] I have read and complied with the project's [AI Policy](https://github.com/music-assistant/.github/blob/main/AI_POLICY.md) for any AI-assisted contributions. - [ ] I have [raised a PR against the documentation repository](https://github.com/music-assistant/music-assistant.io/blob/main/CONTRIBUTING.md) targeting the main or beta branch as appropriate.