From 4b619951ff5e79752cdb31aac9659fb28d7d864e Mon Sep 17 00:00:00 2001 From: Broque Thomas <26755000+Nezreka@users.noreply.github.com> Date: Thu, 23 Apr 2026 16:52:13 -0700 Subject: [PATCH] Fix UnboundLocalError in _check_and_remove_from_wishlist Method 4 When a completed download's track_info has neither an `id` field nor a `wishlist_id`, Methods 1-3 of _check_and_remove_from_wishlist() all skip without defining `wishlist_tracks`. Method 4 (fuzzy match) then hits `if not wishlist_tracks:` and raises UnboundLocalError, which the call sites catch + log but silently skip the wishlist removal for that track. Path became more common after the batch-queue-system refactor started routing non-Spotify-id completions (e.g. discover sync tracks downloaded under a non-Spotify primary source) through the same completion handler. Fix: initialize `wishlist_tracks = []` at the top of the try block so Method 3's reassignment still works and Method 4's `if not wishlist_tracks` guard always has a defined value to test. Credit to RENOxDECEPTION (JohnBaumb) for pinpointing the variable-scope issue during PR #357 testing. --- web_server.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/web_server.py b/web_server.py index 05d577c4..32ba02dc 100644 --- a/web_server.py +++ b/web_server.py @@ -22619,7 +22619,11 @@ def _check_and_remove_from_wishlist(context): # Try to extract Spotify track ID from various sources in the context spotify_track_id = None - + # Populated lazily by Method 3 or Method 4. Initialized here so Method 4's + # `if not wishlist_tracks` guard doesn't UnboundLocalError when Methods 1/2 + # found nothing and Method 3 never ran (no wishlist_id in track_info). + wishlist_tracks = [] + # Method 1: Direct track_info with id track_info = context.get('track_info', {}) if track_info.get('id'):