[Dbix-class] DBIx::Class::Validation exceptions

Ton Voon ton.voon at opsera.com
Thu May 13 01:00:07 GMT 2010


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: DBIx_Class_Validation_exception_error.patch
Type: application/octet-stream
Size: 4287 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20100513/923cd2f6/DBIx_Class_Validation_exception_error.obj
-------------- next part --------------



More information about the DBIx-Class mailing list