Description
When a subscriber receives a message, the API says it has an 'attributes' member that is a dict:
However, it is not, in fact, a dict; it is a protobuf map. The behaviour is quite different, which the Python protobuf API documentation explains at some length:
https://developers.google.com/protocol-buffers/docs/reference/python-generated#map-fields
This is not a small difference... the semantic gap is substantial, because using the .attributes
type in place of a dict breaks code like this:
message_rev = None
if some_condition:
try:
message_rev = int(message.attributes['revision'])
except KeyError:
message_rev = DEFAULT
In this case, instead of assigning the value DEFAULT
, this code simply raises a new exception that doesn't happen with dicts (it's a ValueError, because the try-block will execute int('')
). This is an incompatible, breaking change.
Again, this is a subtle, but important, API difference. At a minimum, it seems like the PubSub API docs should point to the Protobuf docs, instead of simply listing the incorrect type.