2

Due to legacy code I'm uploading database cache from my local machine to production. However as I'm using python 3.9 and production is running python 3.7, I'm running into "unsupported pickle protocol" errors when the cache is used (ValueError: unsupported pickle protocol: 5).

Is there any way to set the pickle version on my local to match the version? or any method to transform it? ...or am I stuck installing and using python 3.7 for this project?

Ben
  • 2,348
  • 1
  • 20
  • 23
  • 1
    [This](https://stackoverflow.com/a/25843743/6759844) might help – Brian Destura Aug 18 '21 at 00:38
  • Thanks for the comment @bdbd , in the end modifying the Django db cache ended up appearing more complicated than installing 3.7 and rerunning the cache builder. – Ben Aug 19 '21 at 19:50

1 Answers1

0

From the documentation:

The default pickle protocol is -1, which is the highest and latest version. This value should be pinned to a specific protocol number, since -1 means different things between versions of Python.

Default pickle protocol for python3.7 is 4. And the default for python3.9 is 5. You can pin the pickle protocol here:

CACHES = {
    'default': {
        'OPTIONS': {
            'PICKLE_VERSION': 4,
            ...
        },
        ...
    },
}
Harshal Parekh
  • 5,918
  • 4
  • 21
  • 43
  • Does this work if I'm using Django's DB cache? Or would I need to be using Redis? – Ben Jul 19 '23 at 06:30