Tuesday, April 24, 2012

How to avoid race conditions when using the find_or_create method of DBIx::Class::ResultSet?

From the documentation for find_or_create:




Note: Because find_or_create() reads from the database and then
possibly inserts based on the result, this method is subject to a race
condition. Another process could create a record in the table after
the find has completed and before the create has started. To avoid
this problem, use find_or_create() inside a transaction.




Is it enough to just use find_or_create() inside a transaction in PostgreSQL?





No comments:

Post a Comment