I have a simple dictionary that i am trying to save to cache and looks like it django is trying to pickle:
podcasts = []
for i in items:
s = re.sub('[\s+]', '', str(i))
s2 = re.findall(r'<link/>(.*?)<itunes',s)[0]
item_obj = {}
item_obj['title'] = title
item_obj['url'] = s2
item_obj['created_at'] = created_at
item_obj['duration'] = duration
podcasts.append(item_obj)
This has a very simple format that outputs:
[{'title': "Podcast1", 'url': 'https://example.com\\n', 'created_at': 'Thu, 28 Dec 2017', 'duration': '00:30:34'}]
I am running this from a custom management command like this:
python3 manage.py podcast_job
I attempt to save to cache:
podcasts = get_podcasts()
print(podcasts)
cache.set('podcasts', podcasts)
I get the error:
File "podcast_job.py", line 13, in handle
cache.set('podcasts', podcasts)
File "python3.6/site-packages/django_redis/cache.py", line 33, in _decorator
return method(self, *args, **kwargs)
File "python3.6/site-packages/django_redis/cache.py", line 68, in set
return self.client.set(*args, **kwargs)
File "python3.6/site-packages/django_redis/client/default.py", line 109, in set
nvalue = self.encode(value)
File "python3.6/site-packages/django_redis/client/default.py", line 329, in encode
value = self._serializer.dumps(value)
File "python3.6/site-packages/django_redis/serializers/pickle.py", line 33, in dumps
return pickle.dumps(value, self._pickle_version)
RecursionError: maximum recursion depth exceeded while calling a Python object
If I try to save with a string I get no error and it saves fine:
cache.set('podcasts', str(podcasts))
How can I save the list of dictionaries and not get the error above?