From: Rafael Kitover Date: Sat, 11 Jun 2011 16:50:50 +0000 (-0400) Subject: don't mask missing deps with datetime_undef_if_invalid X-Git-Tag: v0.08193~17 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=24f5cbcb3f001980062d17f8e4fc6fb4f10a9878 don't mask missing deps with datetime_undef_if_invalid --- diff --git a/Changes b/Changes index 9083f4e..82c72c5 100644 --- a/Changes +++ b/Changes @@ -20,6 +20,8 @@ Revision history for DBIx::Class - Fix a bug in update_all() resulting in the first row receiving a different dataset than the subsequent ones - Accomodate MSAccess supporting only 'INNER JOIN' (not plain 'JOIN') + - InflateColumn::DateTime option datetime_undef_if_invalid no longer + masks missing dependency exceptions (RT#66823) 0.08192 2011-05-10 04:20 (UTC) * Fixes diff --git a/lib/DBIx/Class/InflateColumn/DateTime.pm b/lib/DBIx/Class/InflateColumn/DateTime.pm index 1b72ac6..0ceb679 100644 --- a/lib/DBIx/Class/InflateColumn/DateTime.pm +++ b/lib/DBIx/Class/InflateColumn/DateTime.pm @@ -169,13 +169,10 @@ sub register_column { inflate => sub { my ($value, $obj) = @_; - my $dt = try - { $obj->_inflate_to_datetime( $value, $infcopy ) } - catch { - $self->throw_exception ("Error while inflating ${value} for ${column} on ${self}: $_") - unless $infcopy->{datetime_undef_if_invalid}; - undef; # rv - }; + # propagate for error reporting + $infcopy->{__dbic_colname} = $column; + + my $dt = $obj->_inflate_to_datetime( $value, $infcopy ); return (defined $dt) ? $obj->_post_inflate_datetime( $dt, $infcopy ) @@ -198,8 +195,16 @@ sub _flate_or_fallback my $parser = $self->_datetime_parser; my $preferred_method = sprintf($method_fmt, $info->{ _ic_dt_method }); - my $method = $parser->can($preferred_method) ? $preferred_method : sprintf($method_fmt, 'datetime'); - return $parser->$method($value); + my $method = $parser->can($preferred_method) || sprintf($method_fmt, 'datetime'); + + return try { + $parser->$method($value); + } + catch { + $self->throw_exception ("Error while inflating ${value} for $info->{__dbic_colname} on ${self}: $_") + unless $info->{datetime_undef_if_invalid}; + undef; # rv + }; } sub _inflate_to_datetime { diff --git a/t/inflate/datetime_missing_deps.t b/t/inflate/datetime_missing_deps.t new file mode 100644 index 0000000..680a3f1 --- /dev/null +++ b/t/inflate/datetime_missing_deps.t @@ -0,0 +1,21 @@ +use strict; +use warnings; + +use Test::More; +use Test::Exception; +use lib qw(t/lib); +use DBICTest; + +my $no_class = '_DBICTEST_NONEXISTENT_CLASS_'; + +my $schema = DBICTest->init_schema(); +$schema->storage->datetime_parser_type($no_class); + +my $event = $schema->resultset('Event')->find(1); + +# test that datetime_undef_if_invalid does not eat the missing dep exception +throws_ok { + my $dt = $event->starts_at; +} qr{Can't locate ${no_class}\.pm}; + +done_testing; diff --git a/t/lib/DBICTest/Schema/Event.pm b/t/lib/DBICTest/Schema/Event.pm index 30472d1..29bf11d 100644 --- a/t/lib/DBICTest/Schema/Event.pm +++ b/t/lib/DBICTest/Schema/Event.pm @@ -12,7 +12,7 @@ __PACKAGE__->add_columns( id => { data_type => 'integer', is_auto_increment => 1 }, # this MUST be 'date' for the Firebird and SQLAnywhere tests - starts_at => { data_type => 'date' }, + starts_at => { data_type => 'date', datetime_undef_if_invalid => 1 }, created_on => { data_type => 'timestamp' }, varchar_date => { data_type => 'varchar', size => 20, is_nullable => 1 },