Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions beets/metadata_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,13 @@ def _search_api(
if self.config["search_query_ascii"].get():
query = unidecode.unidecode(query)

if not query and not filters:
# Items without usable metadata produce an empty search request,

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.

Let's remove or simplify this comment. It's misleading because the query and filters can come from user input, not just from items.

# which APIs reject (e.g. MusicBrainz answers with a 400). Report
# no candidates instead of making a doomed request.
self._log.debug("Skipping search with empty query and filters")
return ()

limit = self.config["search_limit"].get(int)
params = SearchParams(query_type, query, filters, limit)

Expand Down
6 changes: 6 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ Bug fixes
valid date/time string" error instead of crashing with an uncaught
``KeyError``. A ``|`` was being accepted as a relative-date unit due to a
regular expression character-class typo.
- Plugins built on ``SearchApiMetadataSourcePlugin`` (:doc:`plugins/musicbrainz`,
:doc:`plugins/spotify`, :doc:`plugins/deezer` and :doc:`plugins/discogs`) no
longer send a search request when both the query text and the filters are
empty, as happens for items with no artist and title tags. Such a request

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.

Please shorten the changelog entry. I would remove everything after empty, as it is not totally accurate. See also https://github.com/beetbox/beets/pull/6873/changes#r3682836514

cannot match anything and MusicBrainz rejects it with ``400 Bad Request``;
these searches now report no candidates instead. :bug:`6862`

..
For plugin developers
Expand Down
8 changes: 8 additions & 0 deletions test/test_metadata_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ def test_search_api_raises_when_raise_on_error_enabled(
with pytest.raises(ValueError, match="Search failure"):
search_plugin._search_api("track", "query", {})

def test_search_api_skips_request_without_query_and_filters(
self, config, search_plugin
):
"""Empty searches are rejected by APIs, so do not send them."""
config["raise_on_error"] = True

assert search_plugin._search_api("track", "", {}) == ()


def test_albums_for_ids_calls_each_plugin_once(monkeypatch):
start_workers = Event()
Expand Down
Loading