Can't pickle local object 'monta_cardapio_por_secao.<locals>.<lambda>'
dnspinheiro opened this issue · 2 comments
When call the endpoint that use cache_page, throw this error. When call others enpoints that too use cache_page, not throw this error, only this endpoint.
I'm using pymemcached 4.0.0, but used 3.4.4, 3.5.0, 3.5.1 and 3.5.2 error persist.
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/core/handlers/base.py", line 204, in _get_response
response = response.render()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/template/response.py", line 107, in render
newretval = post_callback(retval)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/utils/decorators.py", line 144, in callback
return middleware.process_response(request, response)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/middleware/cache.py", line 111, in process_response
response.add_post_render_callback(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/template/response.py", line 92, in add_post_render_callback
callback(self)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/middleware/cache.py", line 112, in
lambda r: self.cache.set(cache_key, r, timeout)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/core/cache/backends/memcached.py", line 82, in set
if not self._cache.set(key, value, self.get_backend_timeout(timeout)):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pymemcache/client/hash.py", line 344, in set
return self._run_cmd("set", key, False, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pymemcache/client/hash.py", line 322, in _run_cmd
return self._safely_run_func(client, func, default_val, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pymemcache/client/hash.py", line 211, in _safely_run_func
result = func(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pymemcache/client/base.py", line 475, in set
return self._store_cmd(b"set", {key: value}, expire, noreply, flags=flags)[key]
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pymemcache/client/base.py", line 1196, in _store_cmd
data, data_flags = self.serde.serialize(key, data)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pymemcache/serde.py", line 119, in serialize
return self._serialize_func(key, value)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pymemcache/serde.py", line 58, in _python_memcache_serializer
pickler.dump(value)
AttributeError: Can't pickle local object 'monta_cardapio_por_secao..'
Problem with function lambda, only rewrite function without 'lambda'
See footnote 2 https://docs.python.org/3/library/pickle.html#what-can-be-pickled-and-unpickled
This is why lambda functions cannot be pickled: all lambda functions share the same name: .