Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

Singular duplicate in paginated current user playlists

Singular duplicate in paginated current user playlists

Plan

Premium

Country

United States

Device

DELL G5 5500

Operating System

Microsoft Windows 11 Home

 

My Question or Issue

I'm using the TypeScript SDK (@spotify/**bleep**) to write a simple application. I wrote a function to get all of the current user's playlists:

 

 

 

import { Page, SimplifiedPlaylist, SpotifyApi } from "@spotify/web-api-ts-sdk";

export async function listUserPlaylists(
  spotify: SpotifyApi,
): Promise<SimplifiedPlaylist[]> {
  // TODO: For some reason, this yields a duplicate, but ONLY between the first
  // and second pages. The last playlist of the first page and first playlist of
  // the second page is always the same, no matter what `limit` I try with.
  async function* iterUserPlaylists(): AsyncGenerator<SimplifiedPlaylist> {
    const limit = 5; // TEMP: small number to test pagination.
    let offset = 0;
    let page: Page<SimplifiedPlaylist>;
    do {
      console.log(`OFFSET IS NOW ${offset}`);
      page = await spotify.currentUser.playlists.playlists(limit, offset);
      for (const playlist of page.items) {
        console.log(`Yielding ${playlist.id}`);
        yield playlist;
      }
      offset += page.items.length;
    } while (page.next !== null);
  }

  const playlists: SimplifiedPlaylist[] = [];
  for await (const playlist of iterUserPlaylists()) {
    playlists.push(playlist);
  }

  return playlists;
}

 

 

 

In other words, this function basically collects playlists from the pages returned by the API into a single array. However, there's an interesting bug. The last playlist of the first page and the first playlist of the second page are always the same. That is, the print statements above give something like this (IDs abbreviated):

 

 

 

OFFSET IS NOW 0
Yielding 5FpuSaX...
Yielding 2lqJXz2...
Yielding 37i9dQZ...
Yielding 3JpajNp...
Yielding 065falt... // <-- THESE ARE THE SAME
OFFSET IS NOW 5
Yielding 065falt... // <-- THESE ARE THE SAME
Yielding 1RPJbcJ...
Yielding 37i9dQZ...
Yielding 7JcOISX...
Yielding 2X68da6...
OFFSET IS NOW 10
Yielding 4GknCaI...
Yielding 5hYYpZ2...
Yielding 37i9dQZ...
Yielding 6sUTQzd...
Yielding 4AApsy0...
OFFSET IS NOW 15
Yielding 37i9dQZ...
Yielding 6Ce4BCm...
Yielding 27e31bd...
Yielding 0vPgi1o...
Yielding 0CfW0t7...
// More output not shown.

 

 

 

This happens no matter what `limit` I try (e.g. 5 per page, 7 per page, 10 per page, etc.); the first and second pages always have that one duplicate. I tried rewriting it without the async generator, by using recursion etc. but they're all functionally equivalent. Is there a problem in my implementation logic? Or is this a bug in the endpoint?

Reply
4 Replies

This recently broke my application and looks like a bug on Spotify's side.It doesn't matter if you use the get current user playlists or the get user playlists, the outcome is the same, always between first and second page.

 

How is it possible to fill a bug report?

I'm also having this issue. I'm using the 'next' property to fetch the next page of playlists and get a singular duplicate playlist. If I reduce the `limit` parameter and increase the number of fetch requests, I get more duplicates between the requests.

What's interesting in my case is that the `total` response field also seems to count those duplicates. ie., when I load the first page, the `total` might be 584 (meaning 584 playlists), but after loading all 10-ish pages, my array has 584 playlists INCLUDING duplicates. So really there are 582 unique (notice that I don't have a duplicate for every single page; for some reason only some of my pages get a duplicate). So the fact that the `total` includes duplicates before it even does all the pagination makes the underlying cause very confusing to me.

Same here, I am having the exact same issue on a premium plan, surprisingly enough, it does not happen on free plans, and this is making our React app go funky as well.

Suggested posts