简体   繁体   中英

get_or_create in Peewee

The paragraph titled Get or create on the peewee documentation says:

While peewee has a get_or_create() method, this should really not be used outside of tests as it is vulnerable to a race condition. The proper way to perform a get or create with peewee is to rely on the database to enforce a constraint.

And then it goes on with an example that only shows the create part, not the get part.

What is the best way to perform a get or create with peewee?

Everything you are doing inside a transaction is atomic.

So as long as you are calling get_or_create() inside a transaction, that paragraph is wrong.

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