On Mon, Oct 15, 2012 at 1:50 PM, Zheng Li <
dlli...@gmail.com> wrote:
> get_or_create shouldn't give duplicate entry error
> anyone help.
>
This is incorrect, and a common misconception: get_or_create() is not
atomic. If this happens, you will get duplicate key errors:
Thread A calls get_or_create(a='a', b='b')
Thread B calls get_or_create(a='a', b='b')
Thread A get_or_create looks for entry in DB, not found
Thread B get_or_create looks for entry in DB, not found
Thread B creates entry in DB
Thread A get_or_create tries to create entry in DB
Where I say 'thread', you could also read 'process'. If you are
capable of serving multiple requests simultaneously, this can happen,
even if you aren't using threads.
If this is a problem for you, use a transaction aware DB instead of
MySQL. It won't solve the issue, but at least you will be able to
unroll the transaction.
Cheers
Tom