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

MsgPack exception - use_list=False #380

Closed
ahopkins opened this issue Jan 22, 2018 · 5 comments
Closed

MsgPack exception - use_list=False #380

ahopkins opened this issue Jan 22, 2018 · 5 comments

Comments

@ahopkins
Copy link
Contributor

I know you removed the use_list option in the loads method when deserializing. See #370

However, I think it should be added back, even with an overwritable default. Without it, it will cause a difficult to diagnose exception.

Second, I see you added the encoding option. It looks like that is being depracated: https://github.com/msgpack/msgpack-python#deprecating-encoding-option

I would suggest going back to

    @classmethod
    def loads(cls, value, use_list=False):
        """
        Deserialize value using ``msgpack.loads``.

        :param value: bytes
        :returns: obj
        """
        if value is None:
            return None
        return msgpack.loads(value, use_list=use_list)

Furthermore, I am trying to use it with a simple string loaded serializer: aiocache.serializers.MsgPackSerializer. Which, to me means adding some sensible defaults.

{
    'cache': "aiocache.RedisCache",
    'serializer': {
        'class': "aiocache.serializers.MessagePackSerializer"
    },
    'plugins': [
        {'class': "aiocache.plugins.HitMissRatioPlugin"},
        {'class': "aiocache.plugins.TimingPlugin"}
    ],
}
@argaen
Copy link
Member

argaen commented Jan 23, 2018

Hi, I'm working on #379. This will allow you to pass the use_list param for that specific serializer. You will be able to do:

{
    'cache': "aiocache.RedisCache",
    'serializer': {
        'class': "aiocache.serializers.MessagePackSerializer",
        'use_list': False,
    },
    'plugins': [
        {'class': "aiocache.plugins.HitMissRatioPlugin"},
        {'class': "aiocache.plugins.TimingPlugin"}
    ],
}

Regarding encoding, thanks for the tip. But I want to avoid this:

>>> import msgpack
>>> msgpack.dumps('hola')
b'\xa4hola'
>>> msgpack.loads(b'\xa4hola')
b'hola'

If I encode a string, I want a string to be returned. Right now using encoding is the only way I've seen. In version 1.0 there is the raw one but not available in 0.5.1. Once 1.0 is released I'll update it

@ahopkins
Copy link
Contributor Author

Thanks. I love the implementation. I guess I am used to getting the bytes string back having used msgpack in the past. I had to set encoding=None or else I was getting an error.

@argaen
Copy link
Member

argaen commented Jan 23, 2018

Glad its useful.

What do you mean by "getting an error"? encoding=utf-8 is still a valid pattern in 0.5.1

@ahopkins
Copy link
Contributor Author

ahopkins commented Jan 23, 2018 via email

@argaen
Copy link
Member

argaen commented Apr 3, 2018

Closing until we get more data to investigate

@argaen argaen closed this as completed Apr 3, 2018
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

2 participants