【发布时间】:2020-04-04 20:24:59
【问题描述】:
您好,我正在使用将在 appengine 标准上运行的烧瓶框架在 python3 中开发一个应用程序,该标准使用云数据存储进行持久性
我要进行交易
所以我尝试了以下我
@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() 装饰器实体得到更新并且没有错误
【问题讨论】:
-
我可以找到非常相似的issue,它被标记为固定。如果可能的话,我建议在那里打开一个带有详细描述和可重现示例的新问题。在那里它将得到适当的处理。
标签: python-3.x google-app-engine google-cloud-datastore