The problem is this part:
if vote.count(1) == 0:
obj = VoteRecord()
obj.user = user
obj.option = option
obj.put()
Without a transaction, your code could work in this order in two instances of the interpreter:
if vote.count(1) == 0:
obj = VoteRecord()
obj.user = user
if vote.count(1) == 0:
obj = VoteRecord()
obj.user = user
obj.option = option
obj.put()
obj.option = option
obj.put()
Or any strange combination of them. The problem is that the test counter starts again before the start, so the second thread goes through the first part of the conditional expression instead of the second.
, ,
db.run_in_transaction()
.
, , , , , . / Google , , . , . -, , .
, . :
def checkAndLockPage(pageKey):
page = db.get(pageKey)
if page.locked:
return False
else:
page.locked = True
page.put()
return True
, .