Skip to content
Snippets Groups Projects
Commit 5f4452e0 authored by vlorentz's avatar vlorentz
Browse files

Add support for non-str/bytes keys for msgpack >= 1.0.

msgpack 1.0 disables support for non-str/bytes keys by default, but we use
None as key in the output of swh-storage's snapshot_count_branches;
and we use ints in swh-scheduler.
parent abbf366b
No related branches found
Tags v0.0.92
No related merge requests found
......@@ -208,8 +208,13 @@ def msgpack_loads(data: bytes, extra_decoders=None) -> Any:
return obj
try:
return msgpack.unpackb(data, raw=False,
object_hook=decode_types)
try:
return msgpack.unpackb(data, raw=False,
object_hook=decode_types,
strict_map_key=False)
except TypeError: # msgpack < 0.6.0
return msgpack.unpackb(data, raw=False,
object_hook=decode_types)
except TypeError: # msgpack < 0.5.2
return msgpack.unpackb(data, encoding='utf-8',
object_hook=decode_types)
......
......@@ -106,8 +106,12 @@ class Serializers(unittest.TestCase):
self.assertEqual(self.encoded_data, json.loads(data))
def test_round_trip_msgpack(self):
data = msgpack_dumps(self.data)
self.assertEqual(self.data, msgpack_loads(data))
original_data = {
**self.data,
'none_dict_key': {None: 42},
}
data = msgpack_dumps(original_data)
self.assertEqual(original_data, msgpack_loads(data))
def test_round_trip_msgpack_extra_types(self):
original_data = [ExtraType('baz', self.data), 'qux']
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment