GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — pubsub Message class does not set timestamp · Issue #2243 · googleapis/google-cloud-python

pubsub Message class does not set timestamp #2243

New issue
Copy link
New issue
Copy link
Closed
Closed
pubsub Message class does not set timestamp#2243
Copy link
Assignees
tseaver
Labels
api: pubsubIssues related to the Pub/Sub API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Description

@kir-titievsky
kir-titievsky
opened on Sep 2, 2016
Issue body actions

pubsub.Message timestamps are not set. There are two object properties, neither of them is set. What's even more confusing is that attempting to access an attribute of an instance throws an error.

To reproduce:

from gcloud import pubsub
t = pubsub.Client(project='...').topic('${TOPIC}')
# MAY NEED t.create()
s = t.subscription('${SUBSCRIPTION}')
# MAY NEED s.create()
t.publish('test data')  # RETURNS A MSG ID
ack_id, m = s.pull()  # WAS t.pull()

Activity

  1. dhermes
    added
    api: pubsubIssues related to the Pub/Sub API.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on Sep 2, 2016
  2. dhermes
    self-assigned this
    on Sep 2, 2016
  3. dhermes commented on Sep 2, 2016

    @dhermes
    dhermes
    on Sep 2, 2016
    Contributor
    More actions

    Trying to repro right now.

  4. dhermes commented on Sep 2, 2016

    @dhermes
    dhermes
    on Sep 2, 2016
    Contributor
    More actions

    @kir-google-cloud-pubsub I can't reproduce. ack_id, m = s.pull() is essentially invalid, but maybe you meant to say

    pairs = s.pull()
    ack_id, m = pairs[0]

    When I run the slightly modified code, I get

    >>> pub_id = t.publish('test data')
    >>> pub_id
    u'44126525330808'
    >>> msgs = s.pull()
    >>> assert len(msgs) == 1
    >>> ack_id, m = msgs[0]
    >>> m.message_id
    u'44126525330808'
    >>> m.message_id == pub_id
    True
    >>> m.data
    'test data'

    Any more details you can provide?

  5. kir-titievsky commented on Sep 7, 2016

    @kir-titievsky
    kir-titievsky
    on Sep 7, 2016
    Author
    More actions

    You are right -- about the mistake I meant. In your code, try m.timestamp -- it should be set, but is not.

  6. kir-titievsky commented on Sep 7, 2016

    @kir-titievsky
    kir-titievsky
    on Sep 7, 2016
    Author
    More actions

    also, m.service_timestamp

  7. tseaver commented on Sep 7, 2016

    @tseaver
    tseaver
    on Sep 7, 2016
    Contributor
    More actions

    There are two timestamps possible on a message:

    • message.timestamp is in the attributes of the message, and must therefore be set by the topic: setting those is controlled by the topic.timestamp_messages attribute, which defaults to False.
    • message.service_timestamp is set by the back-end, and parsed from the publishTime field of the pulled message resource.

    To activate the first kind:

    from gcloud.pubsub.client import Client
    client = Client(project='...')
    topic = client.topic('${TOPIC}', timestamp_messages=True)
    t.create()
    s = t.subscription('${SUBSCRIPTION}')
    s.create()
    t.publish('test data')
    ack_ids = []
    for ack_id, m in s.pull():
        ack_ids.append(ack_id)
        print(m.data, m.timestamp, m.service_timetamp)
    sub.acknowledge(ack_ids)

    On my box, the previous example yields:

    (datetime.datetime(2016, 9, 7, 20, 42, 18, 810563, tzinfo=<UTC>), 'test_data', None)
    

    That tells me that for some reason the back-end is not setting the publishTime field in the message resource it is returning, but that the timestamp attribute set by the publishing application is being set.

  8. tseaver commented on Sep 7, 2016

    @tseaver
    tseaver
    on Sep 7, 2016
    Contributor
    More actions

    It appears that the GAX/gRPC adapter for pubsub is not mediating between the publish_time field in the PublishedMessage proto and the expected publishTime field (as returned from the JSON-over-HTTP API).

  9. tseaver
    closed this as completedin #2262on Sep 7, 2016
  10. theacodes
    unassigned
    dhermes
    on Sep 28, 2018
  11. JustinBeckwith
    assigned
    tseaver
    on Feb 1, 2021
  12. parthea
    added a commit that references this issue on Mar 6, 2026

    chore(deps): update all dependencies (#2243)

    f98bde7
  13. parthea
    added 2 commits that reference this issue on Apr 1, 2026

    feat: Preserve source names better for more readable sql (#2243)

    677af52

    chore: release 2.30.0 (#2308)

    be79099
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @tseaver
    tseaver

Labels

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

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.