Fixing Django unsupported pickle protocol 4 error
After downgrading Python version used by a Django app that I'm working on, I started getting errors about deserialization, mainly affecting session & cache management.
ValueError at
unsupported pickle protocol: 4
This was due to my database (Postgres) & cache store (Redis) containing values that were serialized using more recent pickle version than the one supported in Python 2.
So the simplest solution was to delete existing sessions & clear cache:
from django.contrib.sessions.models import Session
Session.objects.all().delete()
from django.core.cache import cache
cache.clear()