I am implementing a mechanism to guarantee the uniqueness of property
value (account name of User entity). I am using Model.get_or_insert
mechanism in this process, but the following description in the
document makes me wonder if it is really thread-safe.
| In other words, get_or_insert() is equivalent to this Python code:
|
| def txn():
| entity = MyModel.get_by_key_name(key_name, parent=kwds.get
('parent'))
| if entity is None:
| entity = MyModel(key_name=key_name, **kwds)
| entity.put()
| return entity
|
| return db.run_in_transaction(txn)
I understand that this is thread-safe when I specify a parent, because
both new entity and existing entity share the same parent, which means
both belong to the same entity group.
What I don't understand is the case where I don't specify a parent. In
that case, new entity and existing entity are root entities - which
means there are not in the same entity group. In such a case, it seems
that there is a small chance that two threads see None as the result
of get_by_key_name, and got into a race condition.
It really depends how Google implements Model.get_or_insert(), and I'd
really appreciate if somebody in Google could give me the answer.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---