Skip to content

fix: skip metadata source search when query and filters are empty - #6873

Open
Sanjays2402 wants to merge 2 commits into
beetbox:masterfrom
Sanjays2402:fix/skip-empty-metadata-search
Open

fix: skip metadata source search when query and filters are empty#6873
Sanjays2402 wants to merge 2 commits into
beetbox:masterfrom
Sanjays2402:fix/skip-empty-metadata-search

Conversation

@Sanjays2402

Copy link
Copy Markdown

Description

Fixes #6862.

Items with no artist/title tags produce a search with an empty query and no filters. The request was still sent to the metadata source API, and MusicBrainz answers it with 400 Bad Request, logging a traceback once per affected file. _search_api now returns no candidates instead of issuing a request that cannot match anything.

To Do

  • Documentation (bugfix, no user-facing option changed)
  • Changelog.
  • Tests. (test_search_api_skips_request_without_query_and_filters fails without the fix, passes with it.)

Items with no artist or title tags produce a search with an empty query
and no filters. The request was still sent to the metadata source API,
and MusicBrainz answers it with a 400 Bad Request, which was logged with
a traceback once per affected file during an import.

Return no candidates instead of issuing a request that cannot match
anything.
Copilot AI review requested due to automatic review settings July 25, 2026 00:42
@Sanjays2402
Sanjays2402 requested review from a team and semohr as code owners July 25, 2026 00:42

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

grug see PR fix metadata source search path. When query empty and filters empty, PR now skip API call so no more MusicBrainz 400 spam for junk files with no tags.

Changes:

  • Add guard in SearchApiMetadataSourcePlugin._search_api to return no candidates when query+filters both empty.
  • Add regression test to ensure empty search does not call provider and does not raise even when raise_on_error true.
  • Add changelog entry for bug 🐛6862.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
beets/metadata_plugins.py Skip doomed API request when both query and filters are empty; return empty result set.
test/test_metadata_plugins.py Add regression test covering empty query+filters behavior.
docs/changelog.rst Document the bugfix in the changelog.

Comment thread docs/changelog.rst Outdated
@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.62%. Comparing base (4782acb) to head (98fdff6).
⚠️ Report is 48 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6873      +/-   ##
==========================================
- Coverage   75.64%   75.62%   -0.03%     
==========================================
  Files         163      163              
  Lines       21317    21326       +9     
  Branches     3361     3364       +3     
==========================================
+ Hits        16126    16127       +1     
- Misses       4402     4406       +4     
- Partials      789      793       +4     
Files with missing lines Coverage Δ
beets/metadata_plugins.py 85.02% <100.00%> (+0.27%) ⬆️

... and 9 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread docs/changelog.rst Outdated
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.
- Metadata source searches with neither a query nor any filters (for example

@semohr semohr Jul 28, 2026

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.

This is overstating the impact of the fix. The fix is only applied to the SearchApiMetadataSourcePlugin class which is only used by a limited number of metadata plugin.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair, the entry read as if it covered every metadata source. Reworded in 98fdff6 to name the affected surface explicitly:

Plugins built on SearchApiMetadataSourcePlugin (musicbrainz, spotify, deezer and 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 cannot match anything and MusicBrainz rejects it with 400 Bad Request; these searches now report no candidates instead.

Those four are the only subclasses in-tree. That rewrite also drops the "MusicBrainz'" possessive Copilot flagged above.

Comment thread beets/metadata_plugins.py
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.

Comment thread docs/changelog.rst
- 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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

400 Bad Request when artist/title tags are empty

3 participants