Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shouldn't django's model get_or_create method be wrapped in a transaction?

I was browsing django's source and looked at get_or_create. Shouldn't it be wrapped with a transaction?

Thanks

like image 942
reshefm Avatar asked Feb 16 '11 15:02

reshefm


1 Answers

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.

like image 94
Shawn Chin Avatar answered Oct 24 '22 06:10

Shawn Chin