[Dbix-class] Issue with DBIx::Class::ResultSet::find_or_create():

Christopher H. Laco claco at chrislaco.com
Sat Jul 28 14:30:20 GMT 2007

Matt S Trout wrote:
> On Fri, Jul 27, 2007 at 06:38:19PM -0700, Mesdaq, Ali wrote:
>> This came up in the Catalyst list today so I am posting here for
>> discussion or bug reporting.
>> The issue is that it seems the find_or_create() call can have a hiccup
>> in high load situations where find_or_create is called more than once at
>> the same time with the same value. So what happens is both calls try to
>> do a find and return nothing then they attempt to insert and once
>> succeeds and one gets an error of:
>> DBIx::Class::ResultSet::find_or_create(): DBI Exception:
>> DBD::mysql::st execute failed: Duplicate entry
> =

> My initial response to this was the same as everybody else's, "catch the =
> exception".
> =

> My second response was "can't we make this atomic somehow?" ... but of co=
> the answer is no. We could do transaction stuff and ... throw a different
> exception.
> =

> I don't like your "return -1" approach though.
> =

> Three possiblities:
> =

> (1) trap duplicate key exception and do what you describe
>     - do DBs give a sanely trappable exception here?
> =

> (2) try the re-select no matter what the exception
>     - actually -probably- safe. performance issues?

Ha ha, unless you're using DBD::SQLite 1.13, then the key violation
throws and exception and the next call fails with the same error, even
when it's an unrelated query like a select. Gebus, what a retarded bug
find weekend that was. :-)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 187 bytes
Desc: OpenPGP digital signature
Url : http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20070728/ae=

More information about the Dbix-class mailing list