GeezerVison is showing github.com — [Documentation Issue] Pub/Sub default max_messages is unclear in 0.13.0 docs · Issue #1756 · googleapis/google-cloud-python
[Documentation Issue] Pub/Sub default max_messages is unclear in 0.13.0 docs #1756DescriptionPage Name: pubsub-usage
Release: 0.13.0
This section:
Fetch pending messages for a pull subscription:
>>> from gcloud import pubsub
>>> client = pubsub.Client()
>>> topic = client.topic('topic_name')
>>> subscription = topic.subscription('subscription_name')
>>> with topic.batch() as batch:
... batch.publish('this is the first message_payload')
... batch.publish('this is the second message_payload',
... attr1='value1', attr2='value2')
>>> received = subscription.pull() # API request
>>> messages = [recv[1] for recv in received]
>>> [message.message_id for message in messages]
[<message_id1>, <message_id2>]
>>> [message.data for message in messages]
['this is the first message_payload', 'this is the second message_payload']
>>> [message.attributes for message in messages]
[{}, {'attr1': 'value1', 'attr2': 'value2'}]
Does not pull all pending messages in my very simple test code. It only pulls one pending message. I can get multiple by specifying 'max_messages' greater than 1 in the 'subscription.pull()' call.
Has something changed in the implementation since this doc was written? Activityjoeholley commented on Apr 26, 2016 Tested with two simple scripts: one that publishes one message a second on infinite loop, and one that does subscription.pull() once per 10 seconds on an infinite loop. No args for subscription.pull() results in one message received. Specifying max_messages > 1 will allow me to get multiple in one pull. joeholley commented on Apr 26, 2016 tseaver commented on Apr 26, 2016 Thanks for the report! I will update the docs. dhermes commented on Apr 27, 2016 @tmatsuo Is there a better default than 1 for max_messages?
@tseaver I would give you the line in pubsub-usage.rst where received = subscription.pull() # API request should be changed, but GitHub doesn't allow linking into RST or MD files, so I can't.
@joeholley Do you think a suitable change would be to just change that line to
received = subscription.pull(max_messages=2)
or do you think there should be a separate example showcasing that the default is 1?
@joeholley RE: Subscription.pull shows a default value of 1, that is what's in the actual code. I'm not sure how familiar you are with Sphinx, but most of the module docs are completely generated by Sphinx with no curation by us, and that includes the defaults for keyword arguments. tseaver commented on Apr 28, 2016 dhermes commented on Apr 28, 2016 Nice! I forgot about that. w00t!
So the issue is that 0.13.0 is out of date.
@joeholley Does that resolve your issue? Also, in general, when filing a docs bug, double check latest before filing, since stable and 0.x.y are docs that will be frozen at the time they were generated. changed the title [-][Documentation Issue] [/-] [+][Documentation Issue] Pub/Sub default max_messages is unclear in 0.13.0 docs[/+] on Apr 28, 2016tseaver commented on Apr 28, 2016 tmatsuo commented on May 3, 2016 @dhermes I think it is a mandatory parameter for the core API. Having 1 as a default in this layer seems reasonable. dhermes commented on May 3, 2016 joeholley commented on May 3, 2016 Weird; the click-to-generate-issue functionality I used to make this ticket doesn't actually tell you exactly which docs page (via path) I was referencing.
To be clear, I was referring to http://googlecloudplatform.github.io/gcloud-python/stable/pubsub-usage.html , which AFAICT is
- not an sphinx-genned page,
- is current live on the site, and
- does not reflect the implementation in the lastest version of the gcloud python module that will be pulled by users doing a 'pip install gcloud' today.
So the section I quoted still needs to be updated manually, looks like? In addition there's a portion of the docs a bit after the example quoted where it specifically calls out the max_messages=1 param as a way to get only one message
Fetch a limited number of pending messages for a pull subscription:
>> from gcloud import pubsub
>> client = pubsub.Client()
>> topic = client.topic('topic_name')
>> subscription = topic.subscription('subscription_name')
>> with topic.batch() as batch:
... batch.publish('this is the first message_payload')
... batch.publish('this is the second message_payload',
... attr1='value1', attr2='value2')
>> received = subscription.pull(max_messages=1) # API request
>> messages = [recv[1] for recv in received]
>> [message.message_id for message in messages]
(When that the default behavior, having an example callout referencing it doesn't make sense.)
@tmatsuo No issues with the default being one, just need the docs to reflect that. joeholley commented on May 3, 2016 @tseaver - I can't re-open a github issue I didn't close in this repo since I'm not a repo collaborator :D tseaver commented on May 3, 2016
To be clear, I was referring to http://googlecloudplatform.github.io/gcloud-python/stable/pubsub-usage.html , which AFAICT is
Note that you are referencing the stable version (as of the last release), ratther than the latest version (built from the master branch).
not an sphinx-genned page,
It is generated by Sphinx (see the source). The example snippets are now (on master) pulled from a separate Python script, which allows them to be tested against the actual API.
is current live on the site, and
(see above)
does not reflect the implementation in the lastest version of the gcloud python module that will be pulled by users doing a 'pip install gcloud' today.
The stable version gets updated as we make new releases. joeholley commented on May 3, 2016 Okay, I understand what you're saying here, but the fact remains that someone who uses gcloud python today for the first time and does a 'pip install gcloud' gets different functionality than what is used in examples on the publicly facing docs site. If a new release of gcloud has been cut and put on pip, why has a new release of the docs not been cut and put on the documentation website? Shouldn't these two should be in lockstep to avoid confusion for users? dhermes commented on May 3, 2016 This convention is a very common one (the default one on readthedocs.org). stable is our latest release (the one people get when they pip install) and latest is re-built / re-deployed every time we push to master. joeholley commented on May 4, 2016 I'm really sorry, but I'm still confused. The version I got when running pip install gcloud does not match the documentation I get when I go to http://googlecloudplatform.github.io/gcloud-python/ - in both cases (the package, and the docs), I'm not specifying any version. Shouldn't it be safe for me to assume that the default docs on the doc page are for the default package version pulled via pip? It seems to me that you two are saying that they should match, but in fact it doesn't (or didn't, 8 days ago when I made this issue).
@tseaver said:
To be clear, I was referring to http://googlecloudplatform.github.io/gcloud-python/stable/pubsub-usage.html , which AFAICT is
Note that you are referencing the stable version
which I read as "you are referencing the docs for the 'stable' tagged build of the gcloud python module"
@dhermes said:
This convention is a very common one (the default one on readthedocs.org). stable is our latest release (the one people get when they pip install)
which I read as "when you run pip install, you get the 'stable' tagged build of gcloud python module".
Again, sorry, I'm not trying to be obtuse! These two comments seem to be at odds, since the functionality of the module ('stable' version, as per @dhermes) and the documented functionality ('stable' version, as per @tseaver) don't match? dhermes commented on May 4, 2016 joeholley commented on May 4, 2016 @dhermes
I'm very sorry; apparently I'm failing to explain this in an understandable way. Let me try to mirror your approach. Please follow along if you like, to see the issue at hand.
- Visit googlecloudplatform.github.io/gcloud-python and click the red "Read the Docs" button
- Under 'Pub/Sub' on the left, click 'Using the API'. This takes you to http://googlecloudplatform.github.io/gcloud-python/stable/pubsub-usage.html . Leave this page open, we'll be cutting/pasting code from it in a step below. NOTE: I have not selected any version of the docs page. This is the default version of the docs page any average user will navigate to.
- Open a local shell on any machine where you have the gcloud cli configured and authorized to start GCE instances. Run the following to stand up a fresh GCE instance using the latest official GCE Ubuntu image, and then ssh to that VM. NOTE: this shows that the machine running the example code has no environment customization. It is exactly how an average user would begin with a fresh OS install:
gcloud compute instances create example-instance-2 --machine-type=g1-small --image=ubuntu-15-10 --scope=cloud-platform
gcloud compute ssh example-instance-2
- (now on the GCE instance), Install the default pip package and the default gcloud module. NOTE, we are not specifying any versions here either. These are the default versions any average user will receive when running these commands:
sudo apt-get -y install python-pip && pip install gcloud
- Open an editor and cut/paste the following example code from the page in step 2 (http://googlecloudplatform.github.io/gcloud-python/stable/pubsub-usage.html) into a file named
test.py:
# http://googlecloudplatform.github.io/gcloud-python/stable/pubsub-usage.html
# Fetch pending messages for a pull subscription:
from gcloud import pubsub
client = pubsub.Client()
topic = client.topic('topic_name')
topic.create() # create a new topic as per example page
subscription = topic.subscription('subscription_name')
subscription.create() # create a new subscription as per the example page
with topic.batch() as batch:
batch.publish('this is the first message_payload')
batch.publish('this is the second message_payload', attr1='value1', attr2='value2')
received = subscription.pull() # API request
messages = [recv[1] for recv in received] # Should have received two messages as per the example page
print [message.message_id for message in messages] # Should print two message_ids per the example page
print [message.data for message in messages] # should print two messages per the example page
NOTE: ALL of the above code is VERBATIM from the referenced docs page. As per that docs page, expected output is (again, cut/pasted VERBATIM from the referenced docs page):
[<message_id1>, <message_id2>]
['this is the first message_payload', 'this is the second message_payload']
- Run the test script on the GCE instance, using
python ./test.py.
Observe the output:
[u'32367764065423']
['this is the first message_payload']
I honestly don't know how to make this any clearer. When installing the default version of the gcloud python module from pip, and directly referencing the examples on the default version of the docs that are live on http://googlecloudplatform.github.io/gcloud-python/stable/pubsub-usage.html, the examples given do NOT produce the output from the examples page, and the examples page needs to be updated.
I hope this helps. dhermes commented on May 5, 2016
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|