![](/img/trans.png)
[英]Google Cloud Datastore Python3 AttributeError on include
[英]How to do transactions using on google cloud datastore using google-cloud-ndb library in python3
嗨,我正在使用 flask 框架在 python3 中開發一個應用程序,該框架將在使用雲數據存儲進行持久性的 appengine 標准上運行
我要進行交易
所以我嘗試了以下我
@ndb.transactional()
def update_user(req_data):
print("running for req")
print(req_data)
query = TestUser.query(ndb.AND(TestUser.age=="1"))
with client.context():
result = query.get()
if result.name == "the one":
print("not writing")
return
else:
print(result.name+ " is not equal to 'the one'")
print(result.name)
result.name = req_data["name"]
result.put()
print("transaction ended")
@app.route('/test_req',methods=['POST'])
def test_req_handler():
req_data = request.get_json()
update_user(req_data)
print(req_data)
return "ok"
在本地開發環境中,當我點擊處理程序 /test_req 我收到以下錯誤
\lib\site-packages\google\cloud\ndb\context.py", line 72, in get_context
raise exceptions.ContextError()
google.cloud.ndb.exceptions.ContextError: No current context. NDB calls must be made in context established by google.cloud.ndb.Client.context.
當我刪除 @ndb.transactional() 裝飾器實體得到更新並且沒有錯誤
在原始 Cloud Datastore 中,事務中唯一允許的查詢是祖先查詢。 模擬器仍在執行此限制。 https://cloud.google.com/datastore/docs/upgrade-to-firestore中記錄了此更改。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.