Skip to content
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

Can't pickle local object 'monta_cardapio_por_secao.<locals>.<lambda>' #539

Closed
dnspinheiro opened this issue Aug 25, 2023 · 2 comments
Closed
Labels

Comments

@dnspinheiro
Copy link

dnspinheiro commented Aug 25, 2023

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..'

@dnspinheiro
Copy link
Author

Problem with function lambda, only rewrite function without 'lambda'

@jogo
Copy link
Contributor

jogo commented Aug 25, 2023

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: .

@jogo jogo closed this as completed Aug 25, 2023
@jogo jogo added the invalid label Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants