I want to have unique values in my gae, so i read though the docs and found that “transactions” are atomic.
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
I awalys get the same error
BadRequestError:
Only ancestor queries are allowed inside transactions.
My db model “Account” does not have any ancestors.
Shouldn’t it be the only “ancestor” ?
A way to circumvent this problem would be using the username as the key.