Support format for msgpack < 1.0 in token formatter

msgpack v1.0 changed its data format [1] and during a rolling upgrade, attempts
to unpack cached tokens with old data format with the new default raw=False
result in the following error:

  UnicodeDecodeError: 'utf-8' codec can't decode byte 0x87 in
  position 3: invalid start byte

This passes raw=True to support backward-compat with the old format
until we are guaranteed to have msgpack >= 1.0 in the N-1 release of
a rolling upgrade.

Closes-Bug: #1891244

[1]
https://github.com/msgpack/msgpack-python/blob/v1.0.0/README.md#major-breaking-changes-in-msgpack-10

Change-Id: I6c61df6c097fef698c659c79402c4381ec7f3586
This commit is contained in:
melanie witt 2020-08-11 21:19:01 +00:00
parent 06ab946af5
commit 7d6c71ba26

View File

@ -170,7 +170,15 @@ class TokenFormatter(object):
"""
serialized_payload = self.unpack(token)
versioned_payload = msgpack.unpackb(serialized_payload)
# TODO(melwitt): msgpack changed their data format in version 1.0, so
# in order to support a rolling upgrade, we must pass raw=True to
# to support the old format. The try-except may be removed in the once
# the N-1 release no longer supports msgpack < 1.0.
try:
versioned_payload = msgpack.unpackb(serialized_payload)
except UnicodeDecodeError:
versioned_payload = msgpack.unpackb(serialized_payload, raw=True)
version, payload = versioned_payload[0], versioned_payload[1:]
for payload_class in _PAYLOAD_CLASSES: