Skip to content

How put an array of objects at Google Cloud Datastore? #3361

Description

@gustavorps

OS : Ubuntu 14.04.5
Python: 3.4.3
google-cloud-datastore: 0.24.0

Code example:

fromgoogle.cloudimportdatastoreclassGoogleDatastorePipeline(object):
def__init__(self, settings, stats):
self.client=datastore.Client()
self.batch=self.client.batch()
defopen(self):
self.batch.begin()
defprocess(self):
key=self.client.key('Article')
entity=datastore.Entity(key)
entity['name'] ='A post'entity['content'] ='<html></html>'# How I insert this as array of objects? Can be indexed, if no, no problem.entity['authors'] = [{
'name': 'Author 1', 'type': 'person', },{
'name': 'Author 2', 'type': 'organization', }]
self.batch.put(entity)
defclose(self):
self.batch.commit()

Stacktrace:

File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/twisted/internet/defer.py", line653, in_runCallbackscurrent.result=callback(current.result, *args, **kw)
File"/home/ubuntu/workspace/ze/pipelines/__init__.py", line215, inprocess_itemself.batch.put(entity)
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/cloud/datastore/batch.py", line199, input_assign_entity_to_pb(entity_pb, entity)
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/cloud/datastore/batch.py", line319, in_assign_entity_to_pbbare_entity_pb=helpers.entity_to_protobuf(entity)
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/cloud/datastore/helpers.py", line219, inentity_to_protobuf_set_protobuf_value(value_pb, value)
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/cloud/datastore/helpers.py", line408, in_set_protobuf_valueattr, val=_pb_attr_value(val)
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/cloud/datastore/helpers.py", line325, in_pb_attr_valueraiseValueError("Unknown protobuf attr type %s"%type(val))
ValueError: Unknownprotobufattr type <class'dict'>2017-05-0301:30:16 [scrapy.core.engine] INFO: Closingspider (finished)
2017-05-0301:30:16 [google_auth_httplib2] DEBUG: Makingrequest: POSThttps://accounts.google.com/o/oauth2/token2017-05-0301:30:16 [scrapy.core.engine] ERROR: ScraperclosefailureTraceback (mostrecentcalllast):
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/gax/retry.py", line120, ininnerreturnto_call(*args)
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/gax/retry.py", line68, ininnerreturna_func(*updated_args, **kwargs)
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/grpc/_channel.py", line507, in__call__return_end_unary_response_blocking(state, call, False, deadline)
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/grpc/_channel.py", line455, in_end_unary_response_blockingraise_Rendezvous(state, None, None, deadline)
grpc._channel._Rendezvous: <_RendezvousofRPCthatterminatedwith (StatusCode.INVALID_ARGUMENT, Mutationismissingoperation.)>Duringhandlingoftheaboveexception, anotherexceptionoccurred:
Traceback (mostrecentcalllast):
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/cloud/datastore/_gax.py", line74, in_catch_remap_gax_erroryieldFile"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/cloud/datastore/_gax.py", line173, incommitreturnsuper(GAPICDatastoreAPI, self).commit(*args, **kwargs)
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/cloud/gapic/datastore/v1/datastore_client.py", line345, incommitreturnself._commit(request, options)
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/gax/api_callable.py", line419, ininnerreturnapi_caller(api_call, this_settings, request)
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/gax/api_callable.py", line407, inbase_callerreturnapi_call(*args)
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/gax/api_callable.py", line368, ininnerreturna_func(*args, **kwargs)
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/gax/retry.py", line126, ininner' classified as transient', exception)
google.gax.errors.RetryError: GaxError(Exceptionoccurredinretrymethodthatwasnotclassifiedastransient, causedby<_RendezvousofRPCthatterminatedwith (StatusCode.INVALID_ARGUMENT, Mutationismissingoperation.)>)
Duringhandlingoftheaboveexception, anotherexceptionoccurred:
Traceback (mostrecentcalllast):
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/twisted/internet/defer.py", line653, in_runCallbackscurrent.result=callback(current.result, *args, **kw)
File"/home/ubuntu/workspace/ze/pipelines/__init__.py", line193, inclose_spiderself.batch.commit()
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/cloud/datastore/batch.py", line273, incommitself._commit()
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/cloud/datastore/batch.py", line249, in_commitself.project, mode, self._mutations, transaction=self._id)
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/cloud/datastore/_gax.py", line173, incommitreturnsuper(GAPICDatastoreAPI, self).commit(*args, **kwargs)
File"/usr/lib/python3.4/contextlib.py", line77, in__exit__self.gen.throw(type, value, traceback)
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/cloud/datastore/_gax.py", line82, in_catch_remap_gax_errorsix.reraise(error_class, new_exc, sys.exc_info()[2])
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/six.py", line685, inreraiseraisevalue.with_traceback(tb)
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/cloud/datastore/_gax.py", line74, in_catch_remap_gax_erroryieldFile"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/cloud/datastore/_gax.py", line173, incommitreturnsuper(GAPICDatastoreAPI, self).commit(*args, **kwargs)
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/cloud/gapic/datastore/v1/datastore_client.py", line345, incommitreturnself._commit(request, options)
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/gax/api_callable.py", line419, ininnerreturnapi_caller(api_call, this_settings, request)
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/gax/api_callable.py", line407, inbase_callerreturnapi_call(*args)
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/gax/api_callable.py", line368, ininnerreturna_func(*args, **kwargs)
File"/home/ubuntu/workspace/env/lib/python3.4/site-packages/google/gax/retry.py", line126, ininner' classified as transient', exception)
google.cloud.exceptions.BadRequest: 400Mutationismissingoperation.

Metadata

Metadata

Assignees

Labels

api: datastoreIssues related to the Datastore API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions