Hi!

I'm using DBIx::Class::Validation on our Catalyst app (http://opsview.org ) and I've come across a bug which affects exceptions from an eval.

If I run an eval { txn_do() } which includes a create/update and DBIx::Class::Validation gives an error, then $@ holds the exception, which is also the result of the validation. I'm using Data::FormValidation, so the object class for $@ is Data::FormValidation::Results.

However, the problem is that D::FV::R has an overload for boolean which returns true if the validation was successful. This means that, for instance, txn_do has a check for an eval it is running but 'if ($@)' will return true so it incorrectly thinks there has been no problem and continues processing, rather than failing and propagating $...@.

This doesn't appear to affect FormValidator::Simple.

I had tried to work around this but ended up with a lot of spaghetti code, so this is my attempt at fixing it properly. Please find a patch attached which wraps the exception in a new DBIx::Class::Validation::Exception class which overloads boolean to return "" on success. I've also added an overload for eq and ne which may also be used to check whether $@ contains an error.

I've updated the tests to check for exceptions in $@ and, without the patch, dfv.t has a test failure, but with the patch it works correctly.

I'm sure there must be a cleverer way of doing the exception wrapping, so feel free to change it!

I hope you'll include in a future release.

Ton

Attachment: DBIx_Class_Validation_exception_error.patch
Description: Binary data


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]

Reply via email to