简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM