关键路径元素必须完整 [英] Key Path Element Must be complete
问题描述
我正在研究有关Google云端数据存储区API的一些文档
I'm working through some documentation for the google cloud datastore API
from google.cloud import datastore
datastore_client = datastore.Client(project="PROJECTNAME")
query = datastore_client.query(kind='Video')
r = query.fetch()
for v in r:
key = datastore_client.key('VideosToCollections')
entity = datastore.Entity(key=key)
entity['collection_key'] = key
datastore_client.put(entity)
quit()
但是我在更新条目时收到此错误
However I receive this error when updating an entry
Traceback (most recent call last):
File "fillvideocollections.py", line 20, in <module> datastore_client.put(entity)
File "/usr/local/lib/python2.7/dist-packages/google/cloud/datastore/client.py", line 421, in put
self.put_multi(entities=[entity])
File "/usr/local/lib/python2.7/dist-packages/google/cloud/datastore/client.py", line 448, in put_multi
current.commit()
File "/usr/local/lib/python2.7/dist-packages/google/cloud/datastore/batch.py", line 274, in commit
self._commit()
File "/usr/local/lib/python2.7/dist-packages/google/cloud/datastore/batch.py", line 250, in _commit
self.project, mode, self._mutations, transaction=self._id
File "/usr/local/lib/python2.7/dist-packages/google/cloud/datastore_v1/gapic/datastore_client.py", line 501, in commit
request, retry=retry, timeout=timeout, metadata=metadata
File "/usr/local/lib/python2.7/dist-packages/google/api_core/gapic_v1/method.py", line 143, in __call__
return wrapped_func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/google/api_core/retry.py", line 270, in retry_wrapped_func
on_error=on_error,
File "/usr/local/lib/python2.7/dist-packages/google/api_core/retry.py", line 179, in retry_target
return target()
File "/usr/local/lib/python2.7/dist-packages/google/api_core/timeout.py", line 214, in func_with_timeout
return func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/google/api_core/grpc_helpers.py", line 59, in error_remapped_callable
six.raise_from(exceptions.from_grpc_error(exc), exc)
File "/home/jeffbrubaker/.local/lib/python2.7/site-packages/six.py", line 737, in raise_from
raise value
google.api_core.exceptions.InvalidArgument: 400 Key path element must not be incomplete: [VideosToCollections: ]
我希望上面的代码创建一个VideosToCollections对象作为垫脚石,但将扩展为每个Video创建一个.关于导致上述错误的原因的任何想法,将不胜感激.
I want the code above to create one VideosToCollections object as a stepping stone, but will expand to creating one per Video. Any thoughts on what is causing the above error would be appreciated.
推荐答案
我相信entity['collection_key'] = key
是罪魁祸首(key
是datastore_client.key('VideosToCollections')
,它没有ID,因此路径不完整).也许您打算将其设置为v
的键.所以entity['collection_key'] = v.key
I believe entity['collection_key'] = key
is the culprit (key
is datastore_client.key('VideosToCollections')
which has no ID hence the path is incomplete). Perhaps you meant to set it to the key of v
. So entity['collection_key'] = v.key
这篇关于关键路径元素必须完整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!