[Solved]-Shouldn't django's model get_or_create method be wrapped in a transaction?

4👍

Looking at this diff it looks like as of Revision 8315, that has been handle explicitly within the get_or_create() method.

Update

As @reshefm pointed out, this was properly solved in rev 8670 where force_insert=True was added to obj.save() to ensure that during a race condition, all instances will attempt an insert (and not fall back to update) so only one will succeed while others will fail. Failing instances will proceed to do another get().

In terms of release version, this fix was first introduce in release 1.0.

Leave a comment