Skip to content

Fix Discogs search retry on malformed JSON - #6918

Closed
KKhandelwal1733 wants to merge 1 commit into
beetbox:masterfrom
KKhandelwal1733:fix/discogs-search-retry
Closed

Fix Discogs search retry on malformed JSON#6918
KKhandelwal1733 wants to merge 1 commit into
beetbox:masterfrom
KKhandelwal1733:fix/discogs-search-retry

Conversation

@KKhandelwal1733

Copy link
Copy Markdown

Closes #6912

Problem

The Discogs plugin crashes when the Discogs API returns a malformed JSON response during a search. The json.loads call raises JSONDecodeError, which propagates up and aborts the metadata lookup.

Solution

Wrap the search request in a try/except block that catches json.JSONDecodeError. On the first failure, retry the request once. If the retry also fails, re‑raise the original exception so existing error handling takes over.

Changes

  • beetsplug/discogs/__init__.py — added retry logic around the API call, imported json for the exception type, and documented the behavior.

Testing

  • Added regression tests that simulate a malformed JSON response on the first call and a valid response on the retry, asserting that the search succeeds.
  • Added tests where both attempts return malformed JSON, asserting that the error is propagated.
  • Ran the full test suite on Python 3.14 and verified that linting (ruff, mypy) and documentation builds pass.

File: beetsplug/discogs/__init__.py
@KKhandelwal1733
KKhandelwal1733 requested a review from a team as a code owner August 9, 2026 10:48
@github-actions github-actions Bot added the discogs discogs plugin label Aug 9, 2026
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry.

@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.68%. Comparing base (74c2d98) to head (f376b88).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
beetsplug/discogs/__init__.py 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6918      +/-   ##
==========================================
- Coverage   75.69%   75.68%   -0.02%     
==========================================
  Files         163      163              
  Lines       21412    21415       +3     
  Branches     3384     3384              
==========================================
  Hits        16208    16208              
- Misses       4405     4408       +3     
  Partials      799      799              
Files with missing lines Coverage Δ
beetsplug/discogs/__init__.py 67.37% <0.00%> (-0.63%) ⬇️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@semohr

semohr commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Have you had a chance to discuss this with @treyturner? We generally follow a first-come, first-served approach, and since there’s already a PR addressing this issue, I think it makes sense to continue with the existing one and avoid duplicating the work.

I’ll close this PR for now, but you’re more than welcome to review the existing PR, share your thoughts or suggestions there, and help give it some traction.

@semohr semohr closed this Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

discogs discogs plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants