[Dbix-class] Race condition in find_or_create()

Tobias Kremer list at funkreich.de
Thu Aug 7 09:25:51 BST 2008


Guys, any comments on how we are going to pull this off would be greatly
appreciated :)

Thanks!

--Tobias


Quoting Tobias Kremer <list at funkreich.de>:
> Quoting Ash Berlin <ash_cpan at firemirror.com>:
> > A method on the storage object (which is subclassed to be the
> > particular type of DBI you are connecting to, eg
> > DBIx::Class::Storage::DBI::mysql) which parses and encapsulates the
> > error as returned from the database to mark its type, e.g. FK
> > constraint violation, duplicate key, etc. etc.
> > Then you could check $@->type eq 'duplicate_key' or something.
>
> Sounds good! What do the others think?
>
> I believe I'm not really suited for making these changes deep down in the
> guts
> of DBIC because I know next to nothing about the internals. Maybe somebody
> with
> more knowledge could lay down a more detailed plan which I can use to
> implement?
>
> Currently I understand the proposed solution to work something like this:
>
> 1. Have a _parse_error() method in DBIx::Class::Storage::DBI which takes $@
>    and by default just dies with the error provided.
> DBIx::Class::Storage::DBI
>    subclasses (like mysql) can override this method to return an appropriate,
>    standardized exception object(?) (Can DBIx::Class::Exception be used for
>    this?)
>
> 2. Wrap the dbh_do() call inside DBIx::Class::Storage::DBI's _execute()
>    method with an eval{}.
>
> 3. Afterwards check $@ and, if applicable, utilize _parse_error() to create
>    the standardized exception.
>
> Am I completely off track? :)
>
> --Tobias



More information about the DBIx-Class mailing list