Skip to content

Fix searching within an artist returning no results in Music Assistant - #177673

Open
marcelveldt wants to merge 5 commits into
devfrom
music-assistant-artist-search-filter-test
Open

Fix searching within an artist returning no results in Music Assistant#177673
marcelveldt wants to merge 5 commits into
devfrom
music-assistant-artist-search-filter-test

Conversation

@marcelveldt

@marcelveldt marcelveldt commented Jul 30, 2026

Copy link
Copy Markdown
Member

Proposed change

Searching within an artist in Music Assistant could come back empty even when the artist had matching albums and tracks. An artist search always asks the server for albums and tracks, but the media type surrounding the search decided what was kept from the answer. When that media type was the artist itself, we ended up looking for artists in a response that only held albums and tracks, so everything was dropped.

This is not reachable from the media browser, which reports items as plain music, but it is through the music_assistant.search and media_player.search_media actions.

A related one turned up next to it: a filter is the only part of a search the user picks themselves, but it was ignored whenever a media type came along with it, so narrowing an artist search down to tracks still returned albums.

  • Keep only what an artist can actually hold when searching within one, and ask the server for just that
  • Let a chosen filter win from the media type that merely surrounds the search
  • Return nothing when a filter rules out everything we could look for, instead of quietly widening the search
  • Add tests for searching an artist, with and without the album and track filters

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Copilot AI review requested due to automatic review settings July 30, 2026 19:10
@home-assistant home-assistant Bot added cla-signed code-quality has-tests integration: music_assistant small-pr PRs with less than 30 lines. Top 100 Integration is ranked within the top 100 by usage Top 200 Integration is ranked within the top 200 by usage labels Jul 30, 2026
@home-assistant

Copy link
Copy Markdown
Contributor

Hey there @music-assistant, @arturpragacz, mind taking a look at this pull request as it has been labeled with an integration (music_assistant) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of music_assistant can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign music_assistant Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

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

Adds parameterized coverage for Music Assistant artist-search filtering.

Changes:

  • Tests unfiltered, album-filtered, and track-filtered artist searches.
Comments suppressed due to low confidence (1)

tests/components/music_assistant/test_media_browser.py:482

  • Assert that every artist search requests both album and track media types. The mocked search result ignores the media_types argument, so these cases still pass if _search_within_artist requests only one type; in production the missing type would never be returned and its filter would be empty. Checking the call arguments covers the synchronization this test is intended to protect.
    assert mock_search.call_args.args[0] == "Test Artist - test"
    assert {item.media_class for item in search_results.result} == expected_classes

Comment thread tests/components/music_assistant/test_media_browser.py
Copilot AI review requested due to automatic review settings July 30, 2026 19:16

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

An artist search asks for albums and tracks, but the media type around it
decided what was kept. Coming from an artist that meant looking for artists
in an album and track response, so nothing survived. Keep only what an
artist can actually hold, and ask the server for just that.
Copilot AI review requested due to automatic review settings July 30, 2026 19:21
@marcelveldt marcelveldt changed the title Add test for the Music Assistant artist search filters Fix searching within an artist returning no results in Music Assistant Jul 30, 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

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

Comments suppressed due to low confidence (2)

tests/components/music_assistant/test_media_browser.py:541

  • Remove comments that only narrate the following assertions. The asserted query and media types already make these operations clear.
    # the artist name scopes the query that is sent to the search api
    assert mock_search.call_args.args[0] == "Test Artist - test"
    # a filter narrows what we ask for, instead of asking for everything
    # an artist can hold and dropping most of the response again

homeassistant/components/music_assistant/media_browser.py:676

  • Honor media_filter_classes when the artist content type is also supplied. _get_media_types_from_query prioritizes media_content_type, so an artist query with a track-only filter produces [ARTIST]; this fallback then replaces it with both albums and tracks, returning albums despite the requested filter. The service and websocket APIs allow both fields together.
                media_types = [
                    media_type
                    for media_type in media_types
                    if media_type in ARTIST_MASS_MEDIA_TYPES
                ] or ARTIST_MASS_MEDIA_TYPES

A filter is the only thing the user picks themselves, but it was ignored
whenever a media type came along with it, so filtering an artist search
down to tracks still returned albums.
Copilot AI review requested due to automatic review settings July 30, 2026 19:29

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

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

Comments suppressed due to low confidence (2)

homeassistant/components/music_assistant/media_browser.py:680

  • Preserve an empty intersection for an explicit filter. If an artist-scoped action requests a valid but incompatible class such as artist or playlist, this fallback replaces the user’s filter with albums and tracks, so the response contains media classes the caller explicitly excluded. Only use the artist defaults when no filter was supplied; an incompatible explicit filter should return an empty result without calling the server.
                media_types = [
                    media_type
                    for media_type in media_types
                    if media_type in ARTIST_MASS_MEDIA_TYPES
                ] or ARTIST_MASS_MEDIA_TYPES

homeassistant/components/music_assistant/media_browser.py:660

  • Return no results when the explicit filter contains no supported Music Assistant class. The service and WebSocket schemas accept every MediaClass, so a valid request such as media_content_type=album with an image filter reaches the new filter-first branch, maps to an empty list, and then falls back to every searchable audio type. That both ignores the chosen filter and broadens the search beyond the surrounding type.

This issue also appears on line 676 of the same file.

        # Determine which media types to search
        media_types = _get_media_types_from_query(query)

Asking for something we cannot search for, or for something an artist
cannot hold, quietly widened the search instead of leaving it empty, so
the results held exactly what the filter was meant to keep out.
Copilot AI review requested due to automatic review settings July 30, 2026 19:38

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

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

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

Labels

bugfix cla-signed has-tests integration: music_assistant Quality Scale: bronze small-pr PRs with less than 30 lines. Top 100 Integration is ranked within the top 100 by usage Top 200 Integration is ranked within the top 200 by usage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants