Skip to content

Commit

Permalink
Fix a regression when the Cache class is subclassed
Browse files Browse the repository at this point in the history
  • Loading branch information
sh4nks committed Mar 17, 2021
1 parent e68af2e commit 72642e8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flask_caching/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def _set_cache(self, app: Flask, config) -> None:
import_me = config["CACHE_TYPE"]
if "." not in import_me:
plain_name_used = True
import_me = type(self).__module__ + ".backends." + import_me
import_me = "flask_caching.backends." + import_me
else:
plain_name_used = False

Expand Down
12 changes: 12 additions & 0 deletions tests/test_basic_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
HAS_NOT_REDIS = True


class CustomCache(Cache):
pass

class CustomSimpleCache(SimpleCache):
pass

Expand Down Expand Up @@ -123,3 +126,12 @@ def test_app_custom_cache_backend(app):

with app.app_context():
assert isinstance(cache.cache, CustomSimpleCache)


def test_subclassed_cache_class(app):
# just invoking it here proofs that everything worked when subclassing
# otherwise an werkzeug.utils.ImportStringError exception will be raised
# because flask-caching can't find the backend

# testing for "not raises" looked more hacky like this..
CustomCache(app)

0 comments on commit 72642e8

Please sign in to comment.