Skip to content

PubSub subscription.pull() with return_immediately=True causes KeyError #1781

Closed

Description

@joeholley

Attempting to pull from a subscription of an empty topic with return_immediately set to 'True' causes an exception to be raised. This should return an empty result, not raise a KeyError in the module, correct?

Example code:

#!/usr/bin/env python
from gcloud import pubsub 

# Config 
PUBSUB_TOPIC_NAME = 'deleteme'
PUBSUB_SUB_NAME = 'delete_me'

ack_queues = {}
client = pubsub.Client(project="joeholley-mimus01")
topic = client.topic(PUBSUB_TOPIC_NAME)
sub = topic.subscription(PUBSUB_SUB_NAME)
if not topic.exists():
  topic.create()
if not sub.exists():
  sub.create()
while True:
  recv = sub.pull(return_immediately=True,max_messages=1)
  print "Received!"

Results:

Traceback (most recent call last):
  File "db/db_worker.py", line 135, in <module>
    recv = sub.pull(return_immediately=True,max_messages=1)
  File "/usr/local/lib/python2.7/dist-packages/gcloud/pubsub/subscription.py", line 249, in pull
    self.full_name, return_immediately, max_messages)
  File "/usr/local/lib/python2.7/dist-packages/gcloud/pubsub/connection.py", line 419, in subscription_pull
    return response['receivedMessages']
KeyError: 'receivedMessages'

Expected results:
recv should contain an empty list as per http://googlecloudplatform.github.io/gcloud-python/stable/pubsub-subscription.html

Activity

  1. tseaver commented on May 6, 2016

    @tseaver
    Contributor

    Thanks for the report! Should be fixed on master via dd38d66.

  2. added a commit that references this issue on Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: pubsubIssues related to the Pub/Sub API.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions