From 4fe621e3aa0d69ea39fe1730c9e4dcdf22cc6417 Mon Sep 17 00:00:00 2001 From: "artem.morozov" Date: Sat, 22 Aug 2020 18:41:38 +0300 Subject: [PATCH] msgpack: Add 1.0.0 version support Since msgpack 1.0.0 was released Unpacker does not have strict_map_key param and it is True by default now. It makes the Connector fail with an error: `ValueError: int is not allowed for map key` To solve this issue the __init__ method of the Response object was refactored and the strict_map_key param is added for versions less than 1.0.0 Fixes #155 --- tarantool/response.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tarantool/response.py b/tarantool/response.py index 9516cd39..5e485dae 100644 --- a/tarantool/response.py +++ b/tarantool/response.py @@ -50,16 +50,19 @@ def __init__(self, conn, response): # created in the __new__(). # super(Response, self).__init__() + kwargs = dict(use_list=True) + if msgpack.version >= (1, 0, 0): + # XXX: Explain why it is necessary. + kwargs['strict_map_key'] = False if msgpack.version >= (0, 5, 2) and conn.encoding == 'utf-8': # Get rid of the following warning. # > PendingDeprecationWarning: encoding is deprecated, # > Use raw=False instead. - unpacker = msgpack.Unpacker(use_list=True, raw=False) + kwargs['raw'] = False elif conn.encoding is not None: - unpacker = msgpack.Unpacker(use_list=True, encoding=conn.encoding) - else: - unpacker = msgpack.Unpacker(use_list=True) + kwargs['encoding'] = conn.encoding + unpacker = msgpack.Unpacker(**kwargs) unpacker.feed(response) header = unpacker.unpack()