Re: Race conditions in get_or_create

695 views
Skip to first unread message
Message has been deleted

Ross Lawley

unread,
Jun 23, 2012, 3:19:09 PM6/23/12
to mongoeng...@googlegroups.com
Hi yes there is a race condition in get or create as its two operations. A upsert is probably a better operation, get_or_create mimics Djangos equivalent which also has the same race condition.

Ross

On Saturday, June 23, 2012, Philip Gatt wrote:

I'm sometimes hitting "duplicate key error index" when calling get_or_create. I believe this is cause by a race condition. It first tries to "get" the object, that fails so it tries to create it. 

Has anyone experienced this and is there a standard solution for it?

 File "/u/python/chaturbate/mongoengine/queryset.py", line 832, in get_or_create
   doc.save(write_options=write_options)
 File "/u/python/chaturbate/mongoengine/document.py", line 236, in save
   raise OperationError(message % unicode(err))
OperationError: Tried to save duplicate unique keys (E11000 duplicate key error index: mydb.ban_info.$uid_1  dup key: { : 2480401 })

Reply all
Reply to author
Forward
0 new messages