From c48ac5716b473dd44705d84a630236d49c56c58b Mon Sep 17 00:00:00 2001 From: wizardoesmagic Date: Sun, 28 Dec 2025 07:48:19 +0000 Subject: [PATCH] Fix critical bug in iter_playlist_tracks wave iteration logic - Fixed TypeError where next() was incorrectly called on a range object - Replaced flawed iterator manipulation with clean list-based slicing - Maintains same wave-based pagination functionality for efficiency - Ensures proper handling of large Spotify playlists with multiple pages --- pomice/spotify/client.py | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/pomice/spotify/client.py b/pomice/spotify/client.py index b822ab3..9711ed8 100644 --- a/pomice/spotify/client.py +++ b/pomice/spotify/client.py @@ -286,25 +286,16 @@ class Client: # Fetch pages in rolling waves; yield promptly as soon as a wave completes. wave_size = self._playlist_concurrency * 2 - for i, offset in enumerate(remaining_offsets): - # Build wave - if i % wave_size == 0: - wave_offsets = list( - o for o in remaining_offsets if o >= offset and o < offset + wave_size - ) - results = await asyncio.gather(*[fetch(o) for o in wave_offsets]) - for page_tracks in results: - if not page_tracks: - continue - for j in range(0, len(page_tracks), batch_size): - yield page_tracks[j : j + batch_size] - # Skip ahead in iterator by adjusting enumerate drive (consume extras) - # Fast-forward the generator manually - for _ in range(len(wave_offsets) - 1): - try: - next(remaining_offsets) # type: ignore - except StopIteration: - break + remaining_offsets_list = list(remaining_offsets) + + for i in range(0, len(remaining_offsets_list), wave_size): + wave_offsets = remaining_offsets_list[i : i + wave_size] + results = await asyncio.gather(*[fetch(o) for o in wave_offsets]) + for page_tracks in results: + if not page_tracks: + continue + for j in range(0, len(page_tracks), batch_size): + yield page_tracks[j : j + batch_size] async def get_recommendations(self, *, query: str) -> List[Track]: if not self._bearer_token or time.time() >= self._expiry: