Remove local providers without wiping the entire library#4183
Merged
Conversation
Removing a local (filesystem/jellyfin/plex/opensubsonic) provider reset the entire library database, discarding all items, favorites and playlists from every other provider too. Remove the provider gracefully like any streaming provider instead: strip its provider mappings recursively, delete orphaned items, and remove the provider's images from the metadata of items that are kept.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR changes provider removal cleanup to behave consistently for local providers (filesystem/Jellyfin/Plex/OpenSubsonic) by removing only the deleted provider’s mappings (and related orphaned items), instead of resetting the entire library database, and it also cleans up provider-owned images left behind in stored metadata.
Changes:
- Remove the “full DB reset” shortcut when deleting local providers and perform recursive mapping cleanup instead.
- Strip images belonging to a removed provider instance from persisted item metadata when items remain mapped to other providers.
- Suppress per-item
MEDIA_ITEM_UPDATEDevents during bulk provider cleanup and add tests covering cleanup + event suppression.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
music_assistant/controllers/music.py |
Removes local-provider full DB reset behavior and suppresses per-item update events during bulk cleanup. |
music_assistant/controllers/media/base.py |
Adds task-local suppression flag and removes provider-owned images from stored metadata when mappings are removed. |
tests/core/test_provider_cleanup.py |
Adds tests for mapping cleanup, image stripping behavior, and update-event suppression during provider cleanup. |
The removed provider mapping(s) are themselves a change to the item, so the event must fire regardless of whether any images were stripped. The re-fetch is now only used to pick an accurate payload, not to gate the event.
Comment on lines
+830
to
+832
| if not SUPPRESS_MEDIA_ITEM_UPDATES.get(): | ||
| event_item = await self.get_library_item(db_id) if images_changed else library_item | ||
| self.mass.signal_event(EventType.MEDIA_ITEM_UPDATED, event_item.uri, event_item) |
Comment on lines
+875
to
+877
| if not SUPPRESS_MEDIA_ITEM_UPDATES.get(): | ||
| event_item = await self.get_library_item(db_id) if images_changed else library_item | ||
| self.mass.signal_event(EventType.MEDIA_ITEM_UPDATED, event_item.uri, event_item) |
marcelveldt
added a commit
that referenced
this pull request
Jun 13, 2026
anatosun
pushed a commit
to anatosun/music-assistant-server
that referenced
this pull request
Jun 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this implement/fix?
Removing a local provider (filesystem, Jellyfin, Plex, OpenSubsonic) wiped the entire library database — every item, favorite and playlist from all other providers along with it. This was a deliberate shortcut: local providers store their images as on-disk file paths, and cleaning those references up on removal was non-trivial, so the whole library was reset instead.
Local providers are now removed gracefully, exactly like streaming providers: provider mappings are stripped recursively, items left without any provider are deleted, and images that belonged to the removed provider are removed from the metadata of the items that are kept.
Changes
MEDIA_ITEM_UPDATEDevents during the bulk cleanup to avoid flooding subscribers;MEDIA_ITEM_DELETEDis left intact.Types of changes
bugfixnew-featureenhancementnew-providerbreaking-changerefactordocumentationmaintenancecidependenciesChecklist
pre-commit run --all-filespasses.pytestpasses, and tests have been added/updated undertests/where applicable.music-assistant/modelsis linked.music-assistant/frontendis linked.