-
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
How put an array of objects at Google Cloud Datastore? #3361
Comments
I tested the JSON below on Datastore Entites (https://console.cloud.google.com/datastore/entities/new) and worked! {
"values": [
{
"entityValue": {
"properties": {
"name": {
"stringValue": "NAME1"
},
"type": {
"stringValue": "TYPE1"
}
}
}
},
{
"entityValue": {
"properties": {
"name": {
"stringValue": "NAME2"
},
"type": {
"stringValue": "TYPE2"
}
}
}
}
]
} But in python don't entity['author'] = {
'values': [
{
'entityValue': {
'properties': {
'name': {
'stringValue': 'NAME1'
},
'type': {
'stringValue': 'TYPE1'
}
}
}
},{
'entityValue': {
'properties': {
'name': {
'stringValue': 'NAME2'
},
'type': {
'stringValue': 'TYPE2'
}
}
}
}
]
} Traceback Traceback (most recent call last):
File "/home/ubuntu/workspace/env/lib/python3.4/site-packages/twisted/internet/defer.py", line 653, in _runCallbacks
current.result = callback(current.result, *args, **kw)
File "/home/ubuntu/workspace/ze/pipelines/__init__.py", line 247, in process_item
self.client.put(entity)
File "/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/cloud/datastore/client.py", line 384, in put
self.put_multi(entities=[entity])
File "/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/cloud/datastore/client.py", line 408, in put_multi
current.put(entity)
File "/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/cloud/datastore/batch.py", line 199, in put
_assign_entity_to_pb(entity_pb, entity)
File "/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/cloud/datastore/batch.py", line 319, in _assign_entity_to_pb
bare_entity_pb = helpers.entity_to_protobuf(entity)
File "/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/cloud/datastore/helpers.py", line 219, in entity_to_protobuf
_set_protobuf_value(value_pb, value)
File "/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/cloud/datastore/helpers.py", line 408, in _set_protobuf_value
attr, val = _pb_attr_value(val)
File "/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/cloud/datastore/helpers.py", line 325, in _pb_attr_value
raise ValueError("Unknown protobuf attr type %s" % type(val)) |
Thanks for filing @gustavorps I'll look into it. |
@gustavorps Two things:
I am preemptively closing this issue since the We can re-open and continue discussion if you think there are more things to discuss. |
H/T to @gustavorps for bringing this up in googleapis#3361. Also snuck in a change in `google.cloud.datastore.helpers` to use `six.binary_type` in place of `(str, bytes)`. (It wasn't a Py3 error before because that check came **after** a `six.text_type` check.)
Thx for fas thet replay @dhermes. First Form key = client.key('Article')
entity = datastore.Entity(key)
entity['name'] = 'A post'
entity['content'] = '<html></html>'
author1 = datastore.Entity('author1')
author1['name'] = 'NAME1'
author1['type'] = 'TYPE1'
author2 = datastore.Entity('author2')
author2['name'] = 'NAME2'
author2['type'] = 'TYPE2'
entity['author'] = [author1, author2]
client.put(entity) Traceback
Second Form key = client.key('Article')
entity = datastore.Entity(key)
entity['name'] = 'A post'
entity['content'] = '<html></html>'
author1 = datastore.Entity('author1')
author1['name'] = 'NAME1'
author1['type'] = 'TYPE1'
author2 = datastore.Entity('author2')
author2['name'] = 'NAME2'
author2['type'] = 'TYPE2'
entity['author'] = { 'values': [author1, author2] }
client.put(entity) Traceback
I decided to use the |
|
My bad @dhermes! You can close the issue. |
Cheers! |
H/T to @gustavorps for bringing this up in #3361. Also snuck in a change in `google.cloud.datastore.helpers` to use `six.binary_type` in place of `(str, bytes)`. (It wasn't a Py3 error before because that check came **after** a `six.text_type` check.)
OS : Ubuntu 14.04.5
Python: 3.4.3
google-cloud-datastore: 0.24.0
Code example:
Stacktrace:
The text was updated successfully, but these errors were encountered: