我正在模仿我在Taggable Mixin中找到的交易示例,但它的行为方式并不相同。
def txn():
// statements omitted for brevity
blog_index.put()
new_post = Post(key_name=new_post_key_name, parent=blog_index,
index = new_index, title = new_title,
body = new_body)
new_post.put()
return new_post
def new_post(cls, new_title=None, new_body=None, new_tags=[]):
new_post = db.run_in_transaction(txn)
new_post.tags = new_tags
new_post.put()
在此示例中,new_post
中的txn
通过db.run_in_transaction
返回,然后可以使用它完成某些操作。但我得到了:
TypeError: object is not callable
这使我相信函数run_in_transaction
已分配给new_post
变量,而不是new_post
返回的实际txn
。
db.run_in_transaction
可以返回任何内容,例如来自可调用函数的值吗?
答案 0 :(得分:2)
run_in_transaction
返回被调用函数返回的内容。您需要包含完整的堆栈跟踪和原始代码,以便我们提供帮助。