When a subscriber receives a message, the API says it has an 'attributes' member that is a dict:
https://github.com/GoogleCloudPlatform/google-cloud-python/blob/11e310ab9f63f06252ff2b9ada201fd8c11ce06c/pubsub/google/cloud/pubsub_v1/subscriber/message.py#L36
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.
When a subscriber receives a message, the API says it has an 'attributes' member that is a dict:
https://github.com/GoogleCloudPlatform/google-cloud-python/blob/11e310ab9f63f06252ff2b9ada201fd8c11ce06c/pubsub/google/cloud/pubsub_v1/subscriber/message.py#L36
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
.attributestype in place of a dict breaks code like this: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 executeint('')). 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.