[PR #630] [MERGED] Add deprecation warnings to direct users towards using cache_handler #970

Closed
opened 2026-02-28 00:02:59 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/spotipy-dev/spotipy/pull/630
Author: @tonyaajjackson
Created: 12/30/2020
Status: Merged
Merged: 1/13/2021
Merged by: @stephanebruckert

Base: masterHead: master


📝 Commits (10+)

  • 7afe673 Refactor functions into static methods of AuthBase
  • 5a48891 Create CacheHandler to abstract caching tokens
  • 0f201b6 Merge branch 'master' of github.com:plamere/spotipy
  • b824d6d Fix cache_handler subclass check for Python 2
  • a4ad2db Split assert message to fix line over max length
  • 9d8c455 Split cache handlers into cache_handler.py
  • 58d46eb flake8 and autopep fixes
  • db17532 Fix init to allow importing CacheHandler
  • 5a5970c flake8 fix
  • 62af92b Merge remote-tracking branch 'upstream/master'

📊 Changes

4 files changed (+185 additions, -17 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 examples/app.py (+12 -8)
📝 spotipy/oauth2.py (+121 -9)
📝 tests/unit/test_oauth.py (+51 -0)

📄 Description

When cache_path or username are specified in the constructors of the SpotifyOAuth, SpotifyPKCE, or SpotifyImplicitGrant auth_managers, the constructor creates a CacheFileHandler instance under the hood and sets it as the auth_manager's cache_handler. The user is currently able to create a CacheFileHandler instance in two ways:

  1. By creating it outside the auth_manager constructor and passing it as the cache_handler (new approach)
  2. By passing cache_path and username to the auth_manager constructor (old approach)

Ideally, there would be one and only one obvious way to specify a CacheFileHandler instance. Specifying by passing to the cache_handler allows flexibility in which CacheHandler is used and should be preferred, so passing the cache_path or username to the auth_manager constructor should be deprecated.

This pull request adds deprecation warnings for if cache_handler or username are passed as arguments to SpotifyOAuth, SpotifyPKCE, or SpotifyImplicitGrant. In addition, the flask example is updated to use the cache_handler approach. I did not find other examples that used the cache_path or username arguments to the auth_manager constructors.

In addition, in github.com/plamere/spotipy@9550c8fd86 I accidentally broke the caching functionality in the SpotifyOAUth, SpotifyPKCE, and SpotifyImplicitGrant auth_managers by removing the get_cached_token and _save_token_info methods from the auth_manager classes. Users with existing codebases that use the get_cached_token and _save_token_info methods directly will experience errors if they upgrade spotipy.

This pull request restores the get_cached_token and _save_token_info methods on the three auth_manager classes as aliases for the corresponding methods in the cache_handler. Deprecation warnings are also added to the get_cached_token and _save_token_info methods to direct users to switch to using the new cache_handler approach. "Legacy" tests checking the get_cached_token and _save_token_info methods in the auth_managers are also added to ensure that the old functionality is preserved.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/spotipy-dev/spotipy/pull/630 **Author:** [@tonyaajjackson](https://github.com/tonyaajjackson) **Created:** 12/30/2020 **Status:** ✅ Merged **Merged:** 1/13/2021 **Merged by:** [@stephanebruckert](https://github.com/stephanebruckert) **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (10+) - [`7afe673`](https://github.com/spotipy-dev/spotipy/commit/7afe673f0b5b494d7915e8bb460a8752f6e701d2) Refactor functions into static methods of AuthBase - [`5a48891`](https://github.com/spotipy-dev/spotipy/commit/5a48891dccbab6c4be698930f12cf452f9178bef) Create CacheHandler to abstract caching tokens - [`0f201b6`](https://github.com/spotipy-dev/spotipy/commit/0f201b6e9bf8dc0291b148884455d2acf5e66872) Merge branch 'master' of github.com:plamere/spotipy - [`b824d6d`](https://github.com/spotipy-dev/spotipy/commit/b824d6da19c378175a6a3d11304b1fdb161b01a3) Fix cache_handler subclass check for Python 2 - [`a4ad2db`](https://github.com/spotipy-dev/spotipy/commit/a4ad2db01ee1a857dbce9728998e2e869b08dd97) Split assert message to fix line over max length - [`9d8c455`](https://github.com/spotipy-dev/spotipy/commit/9d8c4554a5515e6eb54fea0881d50406c00f12ab) Split cache handlers into cache_handler.py - [`58d46eb`](https://github.com/spotipy-dev/spotipy/commit/58d46eb5a14ba09491e5c8891283bc55e818dbb4) flake8 and autopep fixes - [`db17532`](https://github.com/spotipy-dev/spotipy/commit/db17532cf17554ac2025bad21856a8e15b2b7147) Fix init to allow importing CacheHandler - [`5a5970c`](https://github.com/spotipy-dev/spotipy/commit/5a5970c43fddae4b2da497e835d639cc521e0fac) flake8 fix - [`62af92b`](https://github.com/spotipy-dev/spotipy/commit/62af92b3d6c63cad626a0afc583f69dde2268344) Merge remote-tracking branch 'upstream/master' ### 📊 Changes **4 files changed** (+185 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `examples/app.py` (+12 -8) 📝 `spotipy/oauth2.py` (+121 -9) 📝 `tests/unit/test_oauth.py` (+51 -0) </details> ### 📄 Description When `cache_path` or `username` are specified in the constructors of the `SpotifyOAuth`, `SpotifyPKCE`, or `SpotifyImplicitGrant` auth_managers, the constructor creates a `CacheFileHandler` instance under the hood and sets it as the auth_manager's `cache_handler`. The user is currently able to create a `CacheFileHandler` instance in two ways: 1. By creating it outside the auth_manager constructor and passing it as the `cache_handler` (new approach) 1. By passing `cache_path` and `username` to the auth_manager constructor (old approach) Ideally, there would be one and only one obvious way to specify a CacheFileHandler instance. Specifying by passing to the `cache_handler` allows flexibility in which `CacheHandler` is used and should be preferred, so passing the `cache_path` or `username` to the auth_manager constructor should be deprecated. This pull request adds deprecation warnings for if `cache_handler` or `username` are passed as arguments to `SpotifyOAuth`, `SpotifyPKCE`, or `SpotifyImplicitGrant`. In addition, the flask example is updated to use the `cache_handler` approach. I did not find other examples that used the `cache_path` or `username` arguments to the auth_manager constructors. In addition, in https://github.com/plamere/spotipy/commit/9550c8fd86314a15d693a3389b68468b17813156 I accidentally broke the caching functionality in the `SpotifyOAUth`, `SpotifyPKCE`, and `SpotifyImplicitGrant` auth_managers by removing the `get_cached_token` and `_save_token_info` methods from the auth_manager classes. Users with existing codebases that use the `get_cached_token` and `_save_token_info` methods directly will experience errors if they upgrade spotipy. This pull request restores the `get_cached_token` and `_save_token_info` methods on the three auth_manager classes as aliases for the corresponding methods in the `cache_handler`. Deprecation warnings are also added to the `get_cached_token` and `_save_token_info` methods to direct users to switch to using the new `cache_handler` approach. "Legacy" tests checking the `get_cached_token` and `_save_token_info` methods in the auth_managers are also added to ensure that the old functionality is preserved. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-28 00:02:59 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#970
No description provided.