FileSystemCache broken in 1.11.1

This issue has been created since 2022-06-06.

FileSystemCache appears to be broken in 1.11.1 (pickle errors) as a result of the cachelib integration.

To reproduce the bug, just use the FileSystemCache as a backend.

When attempting to read an existing key from the cache, you will get an error every time:

Traceback (most recent call last):
  File "test.py", line 30, in get
    if (c := cache.get(key)) is None:
  File "/usr/local/lib/python3.9/site-packages/flask_caching/__init__.py", line 190, in get
    return self.cache.get(*args, **kwargs)
  File \"/usr/local/lib/python3.9/site-packages/flask_caching/backends/filesystemcache.py\", line 120, in get
    pickle_time = pickle.load(f)
ValueError: unsupported pickle protocol: 198

I believe the bug is caused by the following:

FileSystemCache.get() is overloaded (inherited from CachelibFileSystemCache) but doesn't replicate the same pickle logic as the inherited and non-overloaded CachelibFileSystemCache.set() method. In particular, the set() method stores the pickle_time in the first 4 bytes and then the actual pickle data. The overloaded get() method simply tries to use pickle.load() on the whole thing and blows up due to the first 4 bytes not being "pickle" data.

Environment:

  • Python version: 3.10.4
  • Flask-Caching version: 1.11.1
gumptionthomas wrote this answer on 2022-06-08

I think cachelib 0.7.0 is incompatible with flask-caching 1.11.1 in terms of FileSystemCache.

It looks like this is the cachelib commit that broke the overloaded FileSystemCache.get() implementation. It was committed one day after the commit to filesystemcache.py that made the switch to using cachelib. Doh! :-)

Downgradingcachelib to 0.6.0 resolved this issue for me.

sorenwacker wrote this answer on 2022-06-10

I am getting this error messages even with 1.10.1:

ERROR:flask_caching.backends.filesystemcache:get key 'progress' -> invalid load key, '\x15'.
However, the cache seems to work.
When installing 1.11 it does not work.

northernSage wrote this answer on 2022-06-19

@gumptionthomas Thanks for the detailed write up! Actual issue that caused this problem, though, was the fact that flask-caching install requirements were not yet pinned, which I have just now realized (oops). Fixing it now.

More Details About Repo
Owner Name pallets-eco
Repo Name flask-caching
Full Name pallets-eco/flask-caching
Language Python
Created Date 2016-07-04
Updated Date 2022-09-20
Star Count 745
Watcher Count 16
Fork Count 174
Issue Count 36

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Search workflows that use specific operators 1 2022-04-26 2022-08-11
Questions about image import and structure 7 2021-08-12 2022-08-14
SCM Manager web server not handling spaces in name of files in SVN repo 0 2022-04-19 2022-08-15
Code fails due to certificate issue with server. 0 2022-09-17 2022-09-13
Support for RESTful API that use only Token authentication 2 2018-01-17 2022-09-18
Missing license 0 2021-03-24 2021-12-27
Post MVP- Institution- Education Program and Study Period Offering Enhancements 0 2021-11-30 2022-08-08
Running lando from source 2 2021-09-01 2022-09-24
Proxy fallback ports not working 1 2021-09-02 2022-09-26
Comments in a string are lost 0 2021-10-04 2022-09-08
[BUG] Failed GitHub Action Workflow 2 2022-05-17 2022-09-10
Pending restart text unreadable in dark mode (default theme). 13 2022-05-25 2022-09-15
You have 1 Lovelace elements that are not loaded properly in Lovelace. 2 2022-05-24 2022-09-15
HACS sensor reports 20 updates upon startup 4 2022-05-26 2022-09-29
latest version when use pdg bake mesh to sublevel error 7 2020-10-19 2022-09-21
deleting an hda with pdg link crashes unreal. 2 2020-10-19 2022-09-21
Error in unreal_level_path does not fail gracefully 1 2020-10-22 2022-09-21
here's a work item to do! 0 2022-06-08 2022-08-25
Reorder uses prices exluding tax for customer entered prices regardless of taxsettings 0 2021-09-17 2022-07-19
documentation broken links 1 2022-05-30 2022-07-30
Issue in Contoso Work Template - Getting WARNING: Hub site association failed: Invalid URI: The URI scheme is not valid. 0 2022-01-28 2022-09-28
建议:调整一下界面字体吧,不要用宋体了 7 2021-10-10 2022-01-22
Additional step to finish task #2 3 2022-08-08 2022-09-01
组件slot-scope提示父节点必须为element 7 2021-08-02 2022-09-15
[DOC] Missing important guidance for SSO requirements regarding groups 4 2020-05-07 2022-08-11
Navigation is often uncollapsed by default 1 2022-03-03 2022-09-15
Port old `header.php` features etc 6 2021-12-22 2022-09-24
[BUG]: Split authors that are not in an array 2 2021-08-21 2022-08-21
UnhandledPromiseRejectionWarning: FetchError: request to https://s3.amazonaws.com/ir_public/nsfwjscdn/TFJS_nsfw_mobilenet/tfjs_quant_nsfw_mobilenet/model.json failed, reason: self signed certificate in certificate chain 6 2021-01-19 2022-09-04
Content bug: <TITLE OF PROBLEM> 0 2021-12-24 2022-07-20
BUG: index_col=False does not work 2 2022-04-07 2022-09-17
BUG: `dtype` not being preserved for `replace` on a `CategoricalDtype` 5 2022-04-06 2022-09-25
BUG: `SeriesGroupBy.value_counts` ignore NaNs of groupby column 3 2022-04-07 2022-09-13
BUG: Incosistent handling of null types by PeriodIndex 2 2022-04-06 2022-09-25
`claim_search` has a limit of 50 for `page_size` 3 2021-08-02 2022-09-29
[Feature Request] Popup - adjustable title font size 0 2021-11-22 2022-09-20
Value cannot be null. (Parameter 'provider') 34 2020-09-19 2022-09-22
One question for parameters 0 2021-04-05 2022-09-27
Access to mutable references from tasks via Shared 6 2022-01-18 2022-08-24
Updated `README` 0 2021-08-27 2021-10-11
Lookup in my code ,i got NameError: name 'x' is not defined 1 2022-03-29 2022-09-13
Multiple line selection not working 0 2021-08-09 2022-09-18
Missing Bundles for using Blueprint and OSGiProcessApplication 5 2018-11-28 2022-09-30
increasing PING_BODY_LIMIT=100000 breaks all ping 500 Server error 1 2022-09-01 2022-09-29
Chart categories getting previous categories values on prop changes 0 2021-12-15 2022-09-22
[BUG] React selectors do not work with React 18 0 2022-04-29 2022-09-01
Build failure with `mtl-2.3` 1 2022-01-30 2022-09-26
Missing localization string for id `nav-menu-mobile` 2 2022-07-06 2022-07-22
Kibana Spaces - Loss of data when editing a Space 2 2019-08-02 2022-09-19
Support nuget pack targets in static graph with isolation 1 2021-02-25 2022-08-06