我想在我的gae中拥有独特的价值,所以我通过文档阅读并发现“交易”是原子的。GAE - 祖先问题
https://developers.google.com/appengine/docs/python/ndb/transactions
class Account(ndb.Model):
""""Required DB """
username = ndb.StringProperty(required=True)
password = ndb.StringProperty(required=True)
mail = ndb.StringProperty(required=True)
salt = ndb.StringProperty(required=True)
date = ndb.DateTimeProperty(auto_now_add=True)
name = ndb.StringProperty()
last_name = ndb.StringProperty()
phone_number = ndb.IntegerProperty()
postal = ndb.IntegerProperty()
city = ndb.StringProperty()
products = ndb.IntegerProperty(repeated=True)
@ndb.transactional
def create_account(self):
acc = Account.query(Account.username==self.username)
acc = tuple(acc)
if len(acc)== 0:
self.put()
else:
#yield error
pass
我awalys得到同样的错误
BadRequestError:
Only ancestor queries are allowed inside transactions.
我的数据库模型 “帐户” 没有任何祖先。 它不应该是唯一的“祖先”吗?
您在事务中进行查询。你的查询没有'ancestor'。错误似乎是一致的 – 2012-07-08 20:03:17
所以我不允许在事务内进行查询?然后,我认为我知道的唯一方法是将内容放在内存缓存中(我认为内存缓存也应该是原子的) – 2012-07-09 10:31:42
我没有足够的知识来充分响应您的问题,但是我的计算属性存在相同的问题( s):这会进行查询并返回一个简单的总和。我不得不删除所有交易 并直接投入继续发展。在你的情况下尝试没有装饰者..我们将有更好的答案 – 2012-07-09 12:30:32