From f77066f9a7ba48389446b349bece1e8125d43767 Mon Sep 17 00:00:00 2001 From: Broque Thomas <26755000+Nezreka@users.noreply.github.com> Date: Thu, 12 Mar 2026 09:49:07 -0700 Subject: [PATCH] Fix Spotify rate limit loop causing indefinite API call cycle during ban --- core/spotify_client.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/spotify_client.py b/core/spotify_client.py index c2b50860..fc4ac624 100644 --- a/core/spotify_client.py +++ b/core/spotify_client.py @@ -140,9 +140,19 @@ def rate_limited(func): def wrapper(*args, **kwargs): global _last_api_call_time + # Pre-flight check: if globally rate limited, don't even attempt the API call. + # Let the method body run so its internal is_spotify_authenticated() check + # returns False and iTunes fallback logic can execute. + if _is_globally_rate_limited(): + return func(*args, **kwargs) + max_retries = 5 for attempt in range(max_retries + 1): + # Re-check ban before each retry — a previous attempt may have triggered one + if _is_globally_rate_limited(): + raise SpotifyRateLimitError(0, func.__name__) + # Enforce minimum interval between API calls with _api_call_lock: current_time = time.time()