Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Pub/Sub API lists the wrong (slightly incompatible) type for Message.attributes #4390

Copy link
Copy link
@dlj-NaN

Description

@dlj-NaN
Issue body actions

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.

Metadata

Metadata

Labels

api: pubsubIssues related to the Pub/Sub API.Issues related to the Pub/Sub API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.