From: Peter Rabbitson Date: Wed, 4 Jun 2014 23:10:50 +0000 (+0200) Subject: Do not skip running from_storage filter when a NULL is returned X-Git-Tag: v0.082800~186 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cfa1ab03f5bdd0f14f4eaca99cd002be0020d001;p=dbsrgits%2FDBIx-Class.git Do not skip running from_storage filter when a NULL is returned --- diff --git a/Changes b/Changes index d1f8cdd..2932f71 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,8 @@ Revision history for DBIx::Class * Notable Changes and Deprecations - DBIC::FilterColumn now properly bypasses \'' and \[] literals, just like the rest of DBIC + - DBIC::FilterColumn "from_storage" handler is now invoked on NULLs + returned from storage * Fixes - Fix on_connect_* not always firing in some cases - a race condition diff --git a/lib/DBIx/Class/FilterColumn.pm b/lib/DBIx/Class/FilterColumn.pm index 6fdf1ad..eb46664 100644 --- a/lib/DBIx/Class/FilterColumn.pm +++ b/lib/DBIx/Class/FilterColumn.pm @@ -32,11 +32,7 @@ sub filter_column { sub _column_from_storage { my ($self, $col, $value) = @_; - return $value if ( - ! defined $value - or - is_literal_value($value) - ); + return $value if is_literal_value($value); my $info = $self->column_info($col) or $self->throw_exception("No column info for $col"); diff --git a/t/row/filter_column.t b/t/row/filter_column.t index 066fbfa..26631b4 100644 --- a/t/row/filter_column.t +++ b/t/row/filter_column.t @@ -11,8 +11,8 @@ my $to_storage_ran = 0; my $schema = DBICTest->init_schema( no_populate => 1 ); DBICTest::Schema::Artist->load_components(qw(FilterColumn InflateColumn)); DBICTest::Schema::Artist->filter_column(charfield => { - filter_from_storage => sub { $from_storage_ran++; $_[1] * 2 }, - filter_to_storage => sub { $to_storage_ran++; $_[1] / 2 }, + filter_from_storage => sub { $from_storage_ran++; defined $_[1] ? $_[1] * 2 : undef }, + filter_to_storage => sub { $to_storage_ran++; defined $_[1] ? $_[1] / 2 : undef }, }); Class::C3->reinitialize() if DBIx::Class::_ENV_::OLD_MRO; @@ -118,6 +118,18 @@ CACHE_TEST: { is ($artist->charfield, '8', 'Cache properly blown'); is $from_storage_ran, ++$expected_from, 'from did not run'; is $to_storage_ran, $expected_to, 'to did not run'; + + $artist->update({ charfield => undef }); + is $from_storage_ran, $expected_from, 'from did not run'; + is $to_storage_ran, ++$expected_to, 'to did run'; + + $artist->discard_changes; + is ( $artist->get_column('charfield'), undef, 'Got back null' ); + is ( $artist->charfield, undef, 'Got back null through filter' ); + + is $from_storage_ran, ++$expected_from, 'from did run'; + is $to_storage_ran, $expected_to, 'to did not run'; + } # test in-memory operations