Skip to content

fix: handle missing 'popularity' field in Spotify API response (issue #36)#39

Closed
vanhci wants to merge 1 commit into
ActivityWatch:masterfrom
vanhci:fix/issue-36-popularity-keyerror
Closed

fix: handle missing 'popularity' field in Spotify API response (issue #36)#39
vanhci wants to merge 1 commit into
ActivityWatch:masterfrom
vanhci:fix/issue-36-popularity-keyerror

Conversation

@vanhci

@vanhci vanhci commented May 24, 2026

Copy link
Copy Markdown

Summary

Fixes #36

The Spotify API has deprecated the popularity field in track responses. When this field is missing from the API response, accessing track["item"]["popularity"] raises a KeyError: 'popularity'.

Changes

  • Use .get("popularity") instead of direct dict access to safely handle the missing field
  • Defaults to -1 when the field is absent (preserving the existing fallback behavior)

Testing

This is a runtime fix for a Spotify API deprecation. The field was already removed from newer API responses. The fix ensures backward compatibility with both old and new API responses.

…36)

The Spotify API deprecated the 'popularity' field in track responses.
This caused a KeyError when trying to access track['item']['popularity'].

Use .get() to safely handle missing field, defaulting to -1.
@ErikBjare

Copy link
Copy Markdown
Member

Duplicate of #37 which was just merged

@ErikBjare ErikBjare closed this May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KeyError: 'popularity'

2 participants