我嘗試從命名空間中獲取所有物體,以便在稍后的步驟中洗掉它們。我appengine與datastore和ndblib 一起使用python2.7
我有一個簡單的查詢來獲取所有物體:
def get_entities(namespace_id):
return [entity for entity in ndb.Query(namespace=namespace_id).fetch()]
還對其進行了修改以避免遺留捆綁服務中的dunder kind/entities Datastore Statistics :
def get_entities(namespace_id):
return [entity for entity in ndb.Query(namespace=namespace_id).fetch() if not entity.key.id_or_name.startswith('__')]
使用資料存盤模擬器在本地運行時作業得很好。但是在云中部署時出現此錯誤:
KindError: No model class found for kind '__Stat_Ns_Kind_IsRootEntity__'. Did you forget to import it?
我發現這篇文章Internal Kinds Returned When Retrieving All Entities Belonging to a Particular Namespace但不是一個明確的答案。
如果您有另一種方法來獲取來自特定命名空間的所有物體,我們將受到歡迎!
uj5u.com熱心網友回復:
根據您參考的檔案,它是以兩個下劃線開頭和結尾的種類名稱。
每個統計資訊都可以作為一個物體訪問,其種類名稱以兩個下劃線開頭和結尾
但是,您的代碼正在檢查以下劃線開頭的物體鍵。你應該檢查種類
將您的代碼修改為
return [entity for entity in ndb.Query(namespace=namespace_id).fetch(keys_only=True) if not entity.kind().startswith('__')]
注意:我將您的查詢切換為僅獲取鍵,因為您只想洗掉記錄
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/526429.html
標籤:Google Cloud Collective python-2.7谷歌应用引擎谷歌云平台谷歌云数据存储
下一篇:如何解釋高昂的前端實體成本?
