Skip to content

[pickle] Dump using the highest available protocol #261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flask_caching/backends/memcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def _set(self, key, value, timeout=None):
# I didn't found a good way to avoid pickling/unpickling if
# key is smaller than chunksize, because in case or <werkzeug.requests>
# getting the length consume the data iterator.
serialized = pickle.dumps(value, 2)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm uncertain why this was hardcoded as 2.

serialized = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)
values = {}
len_ser = len(serialized)
chks = range(0, len_ser, self.chunksize)
Expand Down
2 changes: 1 addition & 1 deletion flask_caching/backends/rediscache.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def dump_object(self, value):
t = type(value)
if t == int:
return str(value).encode("ascii")
return b"!" + pickle.dumps(value)
return b"!" + pickle.dumps(value, pickle.HIGHEST_PROTOCOL)

def load_object(self, value):
"""The reversal of :meth:`dump_object`. This might be called with
Expand Down
4 changes: 2 additions & 2 deletions flask_caching/contrib/uwsgicache.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ def delete(self, key):
def set(self, key, value, timeout=None):
return self._uwsgi.cache_update(
key,
pickle.dumps(value),
pickle.dumps(value, pickle.HIGHEST_PROTOCOL),
self._normalize_timeout(timeout),
self.cache,
)

def add(self, key, value, timeout=None):
return self._uwsgi.cache_set(
key,
pickle.dumps(value),
pickle.dumps(value, pickle.HIGHEST_PROTOCOL),
self._normalize_timeout(timeout),
self.cache,
)
Expand Down