From 3e2e8ed0fb76f6606839ced94659e8a1a82e2bf4 Mon Sep 17 00:00:00 2001 From: Ritiek Malhotra Date: Mon, 13 Jan 2020 20:24:53 +0530 Subject: [PATCH 1/2] Trim '?' when extracting ID from HTTP URLs If this excess part isn't trimmed from the ID, it can cause unexpected results when calling some API methods. For example; this code now correctly returns all albums for an artist: ``` artist = 'https://open.spotify.com/artist/7oPftvlwr6VrsViSDV7fJY?si=M3PrzRC4TBOZu8YyLYc-tA' artist_albums = sp.artist_albums(artist) ``` Previously, this code mimicked same behaviour as calling `spotify.artist`, but now will return albums as expected with this commit. Fixes #365 and #323. --- spotipy/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spotipy/client.py b/spotipy/client.py index 6e215f03..86ee137d 100644 --- a/spotipy/client.py +++ b/spotipy/client.py @@ -1128,7 +1128,7 @@ def _get_id(self, type, id): if type != itype: self._warn('expected id of type %s but found type %s %s' % (type, itype, id)) - return fields[-1] + return fields[-1].split('?')[0] return id def _get_uri(self, type, id): From e6829a1139b61a6cef9012254b37331abe7cb94b Mon Sep 17 00:00:00 2001 From: Ritiek Malhotra Date: Mon, 13 Jan 2020 20:25:40 +0530 Subject: [PATCH 2/2] Add a changelog entry for #420 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d954080e..f614f2e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + - Fixed inconsistent behaviour with some API methods when + a full HTTP URL is passed. + ### Changed - Fixed invalid calls to logging warn method - `mock` no longer needed for install. Only used in `tox`.