Skip Menu |

This queue is for tickets about the DBIx-Class CPAN distribution.

Report information
The Basics
Id: 37564
Status: resolved
Worked: 20 min
Priority: 0/
Queue: DBIx-Class

People
Owner: cpan [...] desert-island.me.uk
Requestors: michael [...] ndrix.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.08010
Fixed in: (no value)



Subject: find_or_create race condition
Because find_or_create() reads and then writes based on the result, it is subject to a race condition. If it can't be avoided by changing the implementation, it should probably be mentioned in the documentation to help avoid problems.
Subject: Re: [rt.cpan.org #37564] find_or_create race condition
Date: Sun, 20 Jul 2008 02:11:11 +0100
To: Michael Hendricks via RT <bug-DBIx-Class [...] rt.cpan.org>
From: Matt S Trout <mst [...] shadowcat.co.uk>
On Wed, Jul 09, 2008 at 12:01:25PM -0400, Michael Hendricks via RT wrote: Show quoted text
> Wed Jul 09 12:01:23 2008: Request 37564 was acted upon. > Transaction: Ticket created by MNDRIX > Queue: DBIx-Class > Subject: find_or_create race condition > Broken in: 0.08010 > Severity: Important > Owner: Nobody > Requestors: michael@ndrix.org > Status: new > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=37564 > > > > Because find_or_create() reads and then writes based on the result, it > is subject to a race condition. If it can't be avoided by changing the > implementation, it should probably be mentioned in the documentation to > help avoid problems.
You're right. Fancy writing up some text we can use? (note - it -can- be fixed, but somebody would need to figure out how to parse unique key errors on all supported databases to get it to work, and nobody's yet volunteered to try it on any database at all, sadly) -- Matt S Trout Need help with your Catalyst or DBIx::Class project? Technical Director http://www.shadowcat.co.uk/catalyst/ Shadowcat Systems Ltd. Want a managed development or deployment platform? http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/
On Sat Jul 19 21:11:25 2008, mst@shadowcat.co.uk wrote: Show quoted text
> You're right. Fancy writing up some text we can use?
How about this text for inclusion in DBIx::Class::ResultSet find_or_create documentation. 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. A record can be created in the database after the find has completed and before the create has started. To avoid this problem, use find_or_create() inside a transaction.
Applied doc patch to ResultSet.pm and committed to 0.08/trunk. Thanks!