Reputation: 8481
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?
Upvotes: 2
Views: 2925
Reputation: 180070
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.
Upvotes: 2