-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Documentation Issue] #1723
Comments
Thanks for filing @joeholley! When you say
are you waiting until the As for why you can't retrieve it, the error message explains the issue. Your key >>> from gcloud import datastore
>>> client = datastore.Client(project='YOUR-PROJECT')
>>> key = client.key('Person')
>>> key
<Key[{'kind': 'Person'}], project=YOUR-PROJECT>
>>> id(key)
140413770314320
>>> entity = datastore.Entity(key=key)
>>> entity['name'] = 'Steph Curry'
>>> entity.key
<Key[{'kind': 'Person'}], project=YOUR-PROJECT>
>>> id(entity.key)
140413770314320
>>> client.put(entity)
>>> entity.key
<Key[{'kind': 'Person', 'id': 5675684525506560L}], project=YOUR-PROJECT>
>>> id(entity.key)
140413770315536
>>> id(key)
140413770314320 |
Right; this issue here isn't that I couldn't figure it out. The issue is that the example code on the homepage and the gettting started pages doesn't work!
It's not "my key"; this is literally cut/paste example code from the getting started page. If additional code is needed to make it work, the code should be included in the getting started example, IMO. Basically, just add:
to the end of the example code. Then the homepage code should be similarly updated to either put an entity under the product_key in question, or print the product_key itself rather than the return of client.get(product_key), either of which product meaningful output (rather than 'None'):
output:
|
They work for me. From: http://googlecloudplatform.github.io/gcloud-python/ >>> from gcloud import datastore
>>>
>>> client = datastore.Client()
>>> product_key = client.key('Product', 123)
>>> print(client.get(product_key))
None
>>> From http://googlecloudplatform.github.io/gcloud-python/stable/index.html >>> from gcloud import datastore
>>>
>>> client = datastore.Client()
>>> key = client.key('Person')
>>>
>>> entity = datastore.Entity(key=key)
>>> entity['name'] = 'Your name'
>>> entity['age'] = 25
>>> client.put(entity)
>>>
>>>
>>> # Extra after the example
...
>>> client.get(entity.key)
<Entity[{'kind': u'Person', 'id': 5701829602050048L}] {u'age': 25L, u'name': 'Your name'}>
>>> client.get(key)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/gcloud/datastore/client.py", line 250, in get
deferred=deferred)
File "/usr/local/lib/python2.7/dist-packages/gcloud/datastore/client.py", line 291, in get_multi
transaction_id=transaction and transaction.id,
File "/usr/local/lib/python2.7/dist-packages/gcloud/datastore/client.py", line 123, in _extended_lookup
transaction_id=transaction_id,
File "/usr/local/lib/python2.7/dist-packages/gcloud/datastore/connection.py", line 199, in lookup
_datastore_pb2.LookupResponse)
File "/usr/local/lib/python2.7/dist-packages/gcloud/datastore/connection.py", line 117, in _rpc
data=request_pb.SerializeToString())
File "/usr/local/lib/python2.7/dist-packages/gcloud/datastore/connection.py", line 94, in _request
raise make_exception(headers, error_status.message, use_json=False)
gcloud.exceptions.BadRequest: 400 Key path element must not be incomplete: [Person: ] The only "issue" is the distinction between What would you like to see changed? |
Okay, technically you are correct. The codes examples as they exist do "work". But they are unintentionally misleading. The example on the homepage prints an empty value, and the one on the getting started page does not show you how to retrieve the value you've placed in datastore... in fact, after having come from the homepage, the print method most people would try first ( My suggestions for additions/changes still stand from the previous post.
before the line |
Those two snippets were not intended to be consumed together, so much of the confusion is linked to thinking that they should work together. However, we haven't put much thought into them in general, so I'll dive in and revamp. |
I'll weigh in and say that on any one page - I believe should have enough context in the snippet to make functional sense when put in the shell. A peev of mine (and I don't believe this project is guilty of) is when a given example assumes you have the correct imports that may have been covered somewhere else in the docs. So to me it makes sense to combine the put and get in both places, with a comment over whatever is needed to clarify that this is just helping set context, like dummy data for a unit test. |
Hello, As part of trying to get things under control (as well as to empower us to provide better customer service in the future), I am declaring a "bankruptcy" of sorts on many of the old issues, especially those likely to have been addressed or made obsolete by more recent updates. My goal is to close stale issues whose relevance or solution is no longer immediately evident, and which appear to be of lower importance. I believe in good faith that this is one of those issues, but I am scanning quickly and may occasionally be wrong. If this is an issue of high importance, please comment here and we will reconsider. If this is an issue whose solution is trivial, please consider providing a pull request. Thank you! |
use byte parameters instead of strings
Page Name: index
Release: 0.12.0
I'm just trying to get the example code on the gcloud-python homepage (http://googlecloudplatform.github.io/gcloud-python/) or getting started page (http://googlecloudplatform.github.io/gcloud-python/stable/index.html) to work.
Setup:
I created an n1-standard-1 machine in us-central1-f using the latest ubuntu 1510 image and including the datastore scope. All I've run on it (as root):
I then logged in via my usual user account and ran the interactive python interpreter. First, I tried the homepage example code:
then, the getting started example code:
This pauses, like it has successfully put, but I can't retrieve?
However, if I combine the two code examples, it works:
So, probably need to update one/both of these to be functional for new users?
The text was updated successfully, but these errors were encountered: