Fill total_tracks when Spotify strips it from the playlist object - #21
Open
jonico wants to merge 1 commit into
Open
Fill total_tracks when Spotify strips it from the playlist object#21jonico wants to merge 1 commit into
jonico wants to merge 1 commit into
Conversation
get_playlist_info and playlist_resource both report total_tracks: null, even
for a 65-track playlist. They ask for it via
playlist(fields="...,tracks.total"), and a restricted app does not get that
field back -- requesting it alone yields a bare `{}`.
A one-item page of the items endpoint still reports the true total, so read it
from there when the playlist object withholds it. A reported count is trusted
as-is, so the extra request only happens when the field is actually missing,
and both call sites share one helper so they cannot drift.
Scoped deliberately to the two metadata paths. jamiew#18 already fixes the same
stripped field for get_playlist_tracks' pagination total (jamiew#17), so that call
site is left untouched here to avoid competing with it. get_user_playlists is
also left alone: filling counts there would mean one request per playlist on a
list endpoint.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
jonico
force-pushed
the
fix/playlist-total-count
branch
from
August 25, 2026 17:03
a3b751f to
65a44ec
Compare
This was referenced Aug 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
get_playlist_infoandplaylist_resourceboth reporttotal_tracks: null, even for a 65-track playlist.Both ask for the count via
playlist(fields="id,name,description,owner,public,tracks.total"), and a restricted app doesn't get that field back. Requesting it on its own makes that obvious:The rest of the
fieldslist comes through fine — it's onlytracks.totalthat's stripped.Fix
Read the count off a one-item page of the items endpoint when the playlist object withholds it.
Testing
ruff check,ruff format --check,mypy src/,bandit -r src/all cleanpytest: 171 passed (2 new — one per call site — plus an assertion that a reported count causes no extra lookup)Both previously returned
null.Overlap with #18
I opened this before spotting #17 and #18. #18 fixes the same stripped field for
get_playlist_tracks' pagination total, and does it the same way. To avoid competing with it:get_playlist_tracksis left untouched here — fix: read playlist entries from the "item" key, honor limit by rows #18 owns that call site.get_playlist_infoandplaylist_resourceare changed, which fix: read playlist entries from the "item" key, honor limit by rows #18 doesn't touch, so they'd still reportnullafter it merges.There's a small cosmetic redundancy if both land: #18 reads the total inline, this adds a
spotify_api.playlist_total()helper. Happy to rebase on top of #18 and haveget_playlist_tracksuse the helper too, if you'd prefer one source for it — just say which order you want them in.get_user_playlistsis deliberately left alone: filling counts there would mean one request per playlist on a list endpoint.Note
No
CHANGELOG.mdentry deliberately — I have sibling fixes open (#19, #20) and they'd all conflict on the same lines. Happy to add one to whichever lands first.