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

Make Row object pickable #349

Open
berinhard opened this issue May 6, 2020 · 0 comments
Open

Make Row object pickable #349

berinhard opened this issue May 6, 2020 · 0 comments

Comments

@berinhard
Copy link
Contributor

I was trying to cache rows.table.Row object in a Django project using django-redis but I ran into a serialization error with pickle. Here's the traceback beginning from the relevant entry point, a cache.set call:

~/.virtualenvs/brasil.io/lib/python3.6/site-packages/cache_memoize/__init__.py in inner(*args, **kwargs)
    123                     cache.set(cache_key, True, timeout)
    124                 else:
--> 125                     cache.set(cache_key, result, timeout)
    126                 if miss_callable:
    127                     miss_callable(*args, **kwargs)

~/.virtualenvs/brasil.io/lib/python3.6/site-packages/django_redis/cache.py in _decorator(self, *args, **kwargs)
     30     def _decorator(self, *args, **kwargs):
     31         try:
---> 32             return method(self, *args, **kwargs)
     33         except ConnectionInterrupted as e:
     34             if self._ignore_exceptions:

~/.virtualenvs/brasil.io/lib/python3.6/site-packages/django_redis/cache.py in set(self, *args, **kwargs)
     65     @omit_exception
     66     def set(self, *args, **kwargs):
---> 67         return self.client.set(*args, **kwargs)
     68 
     69     @omit_exception

~/.virtualenvs/brasil.io/lib/python3.6/site-packages/django_redis/client/default.py in set(self, key, value, timeout, version, client, nx, xx)
    109         """
    110         nkey = self.make_key(key, version=version)
--> 111         nvalue = self.encode(value)
    112 
    113         if timeout is DEFAULT_TIMEOUT:

~/.virtualenvs/brasil.io/lib/python3.6/site-packages/django_redis/client/default.py in encode(self, value)
    321 
    322         if isinstance(value, bool) or not isinstance(value, int):
--> 323             value = self._serializer.dumps(value)
    324             value = self._compressor.compress(value)
    325             return value

~/.virtualenvs/brasil.io/lib/python3.6/site-packages/django_redis/serializers/pickle.py in dumps(self, value)
     19 
     20     def dumps(self, value):
---> 21         return pickle.dumps(value, self._pickle_version)
     22 
     23     def loads(self, value):

PicklingError: Can't pickle <class 'rows.table.Row'>: attribute lookup Row on rows.table failed

It would be nice to have this object as a pickleable one so we could cache it without manual parsing.

berinhard added a commit to turicas/brasil.io that referenced this issue May 6, 2020
Precisei fazer a chamada de _asdict porque o objeto rows.table.Row não é pickable.
Criei uma issue na rows endereçando isso:
turicas/rows#349
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant