From 2ae9019b27504d40a51d3e85c12c585670225745 Mon Sep 17 00:00:00 2001 From: Jonathan Cast Date: Mon, 27 Jun 2016 16:43:36 -0500 Subject: [PATCH 1/2] Treat undef like blessed objects for the purpose of looking for special handling --- lib/DBIx/Class/Row.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index 40d6fbd2f..c9b6324da 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -1101,7 +1101,7 @@ sub set_inflated_columns { my ( $self, $upd ) = @_; my $rsrc; foreach my $key (keys %$upd) { - if (ref $upd->{$key}) { + if (!defined $upd->{$key} || ref $upd->{$key}) { $rsrc ||= $self->result_source; my $info = $rsrc->relationship_info($key); my $acc_type = $info->{attrs}{accessor} || ''; From abbcb82c3b076b42893813841938a97cfd77524f Mon Sep 17 00:00:00 2001 From: Jonathan Cast Date: Wed, 29 Jun 2016 10:59:51 -0500 Subject: [PATCH 2/2] Add a test that set_inflated_columns handles undefs on inflated columns properly --- Makefile.PL | 3 +++ t/inflate/undef.t | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 t/inflate/undef.t diff --git a/Makefile.PL b/Makefile.PL index 5ef99487c..c222bdb96 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -85,6 +85,9 @@ my $test_requires = { # 'Sub::Uplevel' => '0.19', + 'DateTime' => '1.18', + 'DateTime::Format::SQLite' => '0.11', + # this is already a dep of n::c, but just in case - used by t/55namespaces_cleaned.t # remove and do a manual glob-collection if n::c is no longer a dep 'Package::Stash' => '0.28', diff --git a/t/inflate/undef.t b/t/inflate/undef.t new file mode 100644 index 000000000..58d0331ad --- /dev/null +++ b/t/inflate/undef.t @@ -0,0 +1,41 @@ +BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } + +use strict; +use warnings; + +use Test::More; + +use DateTime; + +use DBICTest; +my $schema = DBICTest->init_schema(); + +my $date = DateTime->new(year => 1900, month => 1, day => 1); + +my $res = $schema->resultset('Event')->create({ starts_at => $date, created_on => DateTime->now(), }); + +$res->varchar_datetime($date); +is($res->varchar_datetime, $date, 'Setting an inflated column to an object stores the right value in the object'); +isa_ok($res->varchar_datetime, 'DateTime', 'Can store objects in inflated columns'); + +$res->varchar_datetime($date); +$res->varchar_datetime(undef); +is($res->varchar_datetime, undef, 'After storing undef in an object using the accessor, the accessor returns the right value'); +is($res->get_inflated_column('varchar_datetime'), undef, '. . . and get_inflated_column returns the right value'); +is($res->get_column('varchar_datetime'), undef, '. . . and get_column returns the right value'); + +$res->varchar_datetime($date); +$res->set_inflated_columns({ varchar_datetime => undef, }); +is($res->varchar_datetime, undef, 'After storing undef in an object using set_inflated_columns, the accessor returns the right value'); +is($res->get_inflated_column('varchar_datetime'), undef, '. . . and get_inflated_column returns the right value'); +is($res->get_column('varchar_datetime'), undef, '. . . and get_column returns the right value'); + +$res->varchar_datetime($date); +$res->set_inflated_column(varchar_datetime => undef); +is($res->varchar_datetime, undef, 'After storing undef in an object using set_inflated_column, the accessor returns the right value'); +is($res->get_inflated_column('varchar_datetime'), undef, '. . . and get_inflated_column returns the right value'); +is($res->get_column('varchar_datetime'), undef, '. . . and get_column returns the right value'); + +undef $res; + +done_testing();