简体   繁体   English

在Peewee中进行get_or_create

[英]get_or_create in Peewee

The paragraph titled Get or create on the peewee documentation says: peewee文档上标题为Get或create的段落显示:

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. 尽管peewee具有get_or_create()方法,但实际上不应在测试之外使用此方法,因为它容易受到竞争条件的影响。 The proper way to perform a get or create with peewee is to rely on the database to enforce a constraint. 使用peewee执行getcreate的正确方法是依靠数据库强制执行约束。

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? 使用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. 因此,只要您在事务内调用get_or_create() ,该段就是错误的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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