Reputation: 307
When using Google App Engine ndb
, do I have to worry about mixing synchronous and asynchronous put operations in the same function?
e.g. Say that I have some code like this:
class Entity(ndb.Model):
some_flag = ndb.BooleanProperty()
def set_flag():
ent=Entity()
ent.some_flag = False
ent.put_async()
ent.some_flag = True
ent.put()
Does that datastore take care of ensuring that all pending async writes are applied before the synchronous write (so that after set_flag
runs, it is guaranteed that the flag will be True
)? Or is there a race condition because the async put might complete after the synchronous put?
Upvotes: 1
Views: 101
Reputation: 1516
For sample code, and a practical solution, you may have a look at Dan McGrath's reply to the "Cloud Datastore: ways to avoid race conditions" question.
Upvotes: 0
Reputation: 16563
No, the datastore does not take care of this for you.
Even with synchronous puts, calls from different threads can overwrite each other.
I recommend that you read up a bit on transactions, and when and why there are helpful.
Upvotes: 2