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

Pubsub message getting wrong attribute for publishTime #2529

Copy link
Copy link

Description

@sturench
Issue body actions

According the REST docs, a PubsubMessage has the field publishTime

In message.py, from_api_repr is getting the field publishTimestamp below:

instance._service_timestamp = api_repr.get('publishTimestamp')

The current tests are self-confirming of this issue as they simply set up the api_repr with publishTimestamp

A quick fix seems to adjust the following:
message.py

    @classmethod
    def from_api_repr(cls, api_repr):
        """Factory:  construct message from API representation.

        :type api_repr: dict or None
        :param api_repr: The API representation of the message

        :rtype: :class:`Message`
        :returns: The message created from the response.
        """
        data = base64.b64decode(api_repr.get('data', b''))
        instance = cls(
            data=data, message_id=api_repr['messageId'],
            attributes=api_repr.get('attributes'))
        instance._service_timestamp = api_repr.get('publishTime')
        return instance

test_message.py

    def test_from_api_repr_no_attributes(self):
        from base64 import b64encode as b64
        DATA = b'DEADBEEF'
        B64_DATA = b64(DATA)
        MESSAGE_ID = '12345'
        TIMESTAMP = '2016-03-18-19:38:22.001393427Z'
        api_repr = {
            'data': B64_DATA,
            'messageId': MESSAGE_ID,
            'publishTime': TIMESTAMP,
        }
        message = self._getTargetClass().from_api_repr(api_repr)
        self.assertEqual(message.data, DATA)
        self.assertEqual(message.message_id, MESSAGE_ID)
        self.assertEqual(message.attributes, {})
        self.assertEqual(message.service_timestamp, TIMESTAMP)

    def test_from_api_repr_w_attributes(self):
        from base64 import b64encode as b64
        DATA = b'DEADBEEF'
        B64_DATA = b64(DATA)
        MESSAGE_ID = '12345'
        ATTRS = {'a': 'b'}
        TIMESTAMP = '2016-03-18-19:38:22.001393427Z'
        api_repr = {
            'data': B64_DATA,
            'messageId': MESSAGE_ID,
            'publishTime': TIMESTAMP,
            'attributes': ATTRS,
        }
        message = self._getTargetClass().from_api_repr(api_repr)
        self.assertEqual(message.data, DATA)
        self.assertEqual(message.message_id, MESSAGE_ID)
        self.assertEqual(message.service_timestamp, TIMESTAMP)
        self.assertEqual(message.attributes, ATTRS)

I don't currently have a contributor license signed, but will work on that. In the meantime, hoping that someone can pick this up.

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

api: pubsubIssues related to the Pub/Sub API.Issues related to the Pub/Sub API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type
No fields configured for issues without a 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.