Skip to content

Fix stale album links of local files whose album tag changed - #7548

Open
OzGav wants to merge 3 commits into
devfrom
claude/lucid-mendel-x7zef6
Open

OzGav wants to merge 3 commits into
devfrom
claude/lucid-mendel-x7zef6

Conversation

@OzGav

@OzGav OzGav commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

What does this implement/fix?

When the album tag of a Local files track was changed or removed, the library kept the track's link to its old album. A rescan only ever adds album links (_set_track_album inserts into album_tracks and never removes rows, and _update_library_item skips the album step entirely when the new tags have no album).

The "Reconcile duplicate albums" task then re-read such a file through the provider's get_album, hit assert isinstance(full_track.album, Album), and the bare AssertionError escaped every handler, aborting the whole task with an empty failed: message on every run.

Changes:

  • filesystem_local.get_album skips a file whose tags no longer name an album and ends in the existing MediaNotFoundError, which the enrichment and reconcile paths already handle.
  • When a sync re-reads a changed file, its library track is unlinked from this source's albums the file no longer names (_unlink_stale_albums). Albums left empty are removed by the existing end-of-sync orphan cleanup. The link is left alone when the track has more than one file on this source, or when both the track and the album are also on another source, since that source may still place the track on the album.
  • New TracksController.remove_album_link to drop a single track/album link and invalidate both cached listings.

No migration: existing stale links clear up once the affected file is changed and rescanned, or by removing the stale album and syncing again.

Reported in https://github.com/orgs/music-assistant/discussions/7058 (traceback there points at the same assert on stable).

Related issue (if applicable):

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
  • Maintenance / chore — maintenance
  • CI / workflow change — ci
  • Dependencies bump — dependencies

Checklist

  • The code change is tested and works locally.
  • pre-commit run --all-files passes.
  • 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.
  • I have read and complied with the project's AI Policy for any AI-assisted contributions.
  • I have raised a PR against the documentation repository targeting the main or beta branch as appropriate.

Tests were added in tests/providers/filesystem_local/test_stale_album_links.py but have not been run locally yet; relying on CI for this draft.


Generated by Claude Code

A Local files track kept its link to an album after the file's album tag
was changed or removed, because a rescan only ever adds album links. The
"Reconcile duplicate albums" task then re-read such a file through
get_album, hit an assert on the missing album and aborted entirely.

- get_album skips a file whose tags no longer name an album and ends in
  MediaNotFoundError instead of an AssertionError
- a sync of a changed file unlinks its track from this source's albums
  the file no longer names; albums left empty are removed by the existing
  orphan cleanup
- add TracksController.remove_album_link

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014D4KvsSm7CAASBQFYcBLjT
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014D4KvsSm7CAASBQFYcBLjT
@musicassistant-bot

musicassistant-bot Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

✅ The title and description are good to go. Thanks!

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.

🟡 Changes recommended

The rescan cleanup can unlink valid sibling-file album associations and delete shared albums, including other-source mappings and user favorites.

3 open issues
What changed in this PR

This PR addresses stale album associations after local-file album tags change or are removed, and prevents missing album tags from aborting album reconciliation.

Changes:

  • Handles missing album tags with the existing not-found error.
  • Adds stale-link cleanup during local-file sync and a controller method to remove individual links and invalidate cached listings.
  • Adds regression tests for tag changes, shared sources, multiple files, and missing albums.
File Description
tests/​providers/​filesystem_local/​test_stale_album_links.py Adds regression coverage for stale album links and missing tags.
music_assistant/​providers/​filesystem_local/​__init__.py Handles missing album tags and reconciles links after rescanning changed files.
music_assistant/​controllers/​music/​media/​tracks.py Adds single-link removal with album and track listing invalidation.

Review effort: Balanced

@github-actions

This comment was marked as outdated.

- capture the library track before the changed file overwrites it, so a
  second file of the same track is still seen by the guard
- never unlink an album that also has a mapping on another source, so the
  orphan cleanup can not remove a shared album
- read the track's albums through TracksController.get_library_track_albums
  (new unfiltered option) instead of querying album_tracks in the provider
- stub the cache delete in the tests and cover both shared-album variants

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014D4KvsSm7CAASBQFYcBLjT

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.

🟢 Approval recommended

No active review issues were identified for the stale album-link reconciliation changes.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

@OzGav
OzGav requested a review from Bot-MArley November 12, 2026 05:40
@OzGav
OzGav marked this pull request as ready for review November 12, 2026 06:01

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants