【发布时间】:2014-04-29 10:42:03
【问题描述】:
我有一个名为 Conversation 的模型,其中一些字段包括 date_created 和 date_updated 作为 DateTimePropterty 和 auto_now_add 和 auto_now。
如果我使用put() 方法更新模型,date_updated 字段将得到更新。
但是当我使用put_async 方法时,date_updated 字段中的值没有更新。
我也有使用 Python 的 unittest.Testcase 的测试用例,它工作正常。
注意:当我使用 put_async().get_result() 时它可以工作。
示例模型类:
class Conversation(ndb.Model):
participants = ndb.StringProperty(repeated=True)
conversation_name = ndb.StringProperty()
date_created = ndb.DateTimeProperty(required=True, auto_now_add=True)
date_updated = ndb.DateTimeProperty(required=True, auto_now=True)
@staticmethod
def update_conversation_date_by_id(conversation_id):
conversation = Conversation.get_by_id(conversation_id) if conversation_id else None
if conversation is None:
raise CannotFindEntity("Given conversation_id is not found")
else:
conversation.put_async().get
return conversation
【问题讨论】:
标签: google-app-engine python-2.7 google-cloud-datastore