fix: skip metadata source search when query and filters are empty - #6873
fix: skip metadata source search when query and filters are empty#6873Sanjays2402 wants to merge 2 commits into
Conversation
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.
There was a problem hiding this comment.
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_apito 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_errortrue. - 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. |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
🚀 New features to boost your workflow:
|
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 with400 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.
| query = unidecode.unidecode(query) | ||
|
|
||
| if not query and not filters: | ||
| # Items without usable metadata produce an empty search request, |
There was a problem hiding this comment.
Let's remove or simplify this comment. It's misleading because the query and filters can come from user input, not just from items.
| - 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 |
There was a problem hiding this comment.
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
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_apinow returns no candidates instead of issuing a request that cannot match anything.To Do
Documentation(bugfix, no user-facing option changed)test_search_api_skips_request_without_query_and_filtersfails without the fix, passes with it.)