[Dbix-class] find_or_create and unique constraints

Bill Moseley moseley at hank.org
Mon Oct 4 04:16:50 GMT 2010

Finally got back to looking at this today:

On Sun, Oct 3, 2010 at 9:14 AM, Bill Moseley <moseley at hank.org> wrote:

> around '_unique_queries' =3D> sub {
>     my ( $orig, $self, $criteria, $attrs ) =3D @_;
>     my @queries =3D $self->$orig( $criteria, $attrs);
>     return @queries if @queries;
>     my $cols =3D join ', ', keys %{$criteria};
>     $self->throw_exception(
>         "find must provide search criteria that includes primary keys(s) =
> an unique constraint.  Columns [$cols] did not satisfy this requirement"
>     );
> };
That method can be called with an empty hash so I modified to test that and
accept.  There's probably other edge cases where there's problems I have not
considered.  But, running my app's test suite turned up a few places where
find_or_create & update_or_create was not passing a full set of unique keys
(both cases a column had been added to a table and code not updated).

I modified the other code I posted a bit, too (to work with
update_or_create).  All my tests are passing and now running another set of
application automated tests and DBIC tests.  Mid week I can test code on a
few web servers to see if resolves the race conditions I'm seeing under

-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20101003/8ab=

More information about the DBIx-Class mailing list