From: Peter Rabbitson Date: Mon, 8 Nov 2010 11:52:29 +0000 (+0100) Subject: Fix regressions in IC::DT registration logic X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=49bceca3dbc42bc27720f777f336619bd2792943;p=dbsrgits%2FDBIx-Class-Historic.git Fix regressions in IC::DT registration logic --- diff --git a/Changes b/Changes index 23581ad..fb4b43d 100644 --- a/Changes +++ b/Changes @@ -17,6 +17,7 @@ Revision history for DBIx::Class - Refactor handling of RDBMS-side values during insert() - fix regression of inserts into a Postgres / ::Replicated combination - Missing dependency check in t/60core.t (RT#62635) + - Fix regressions in IC::DT registration logic 0.08124 2010-10-28 14:23 (UTC) * New Features / Changes diff --git a/lib/DBIx/Class/InflateColumn/DateTime.pm b/lib/DBIx/Class/InflateColumn/DateTime.pm index 1b0127d..c35f151 100644 --- a/lib/DBIx/Class/InflateColumn/DateTime.pm +++ b/lib/DBIx/Class/InflateColumn/DateTime.pm @@ -109,38 +109,44 @@ the C option in the column info: sub register_column { my ($self, $column, $info, @rest) = @_; + $self->next::method($column, $info, @rest); - return unless defined($info->{data_type}); - my $type; + return unless defined($info->{data_type}); + my $requested_type; for (qw/date datetime timestamp/) { my $key = "inflate_${_}"; next unless exists $info->{$key}; - return unless $info->{$key}; - $type = $_; + return if ! $info->{$key}; + + $requested_type = $_; last; } - unless ($type) { - $type = lc($info->{data_type}); - if ($type eq "timestamp with time zone" || $type eq "timestamptz") { - $type = "timestamp"; - $info->{_ic_dt_method} ||= "timestamp_with_timezone"; - } elsif ($type eq "timestamp without time zone") { - $type = "timestamp"; - $info->{_ic_dt_method} ||= "timestamp_without_timezone"; - } elsif ($type eq "smalldatetime") { - $type = "datetime"; - $info->{_ic_dt_method} ||= "smalldatetime"; - } else { - $info->{_ic_dt_method} ||= $type; - } + my $data_type = lc($info->{data_type} || ''); + + # _ic_dt_method will follow whatever the registration requests + # thus = instead of ||= + if ($data_type eq 'timestamp with time zone' || $data_type eq 'timestamptz') { + $info->{_ic_dt_method} = 'timestamp_with_timezone'; + } + elsif ($data_type eq 'timestamp without time zone') { + $info->{_ic_dt_method} = 'timestamp_without_timezone'; + } + elsif ($data_type eq 'smalldatetime') { + $info->{_ic_dt_method} = 'smalldatetime'; + } + elsif ($data_type =~ /^ (?: date | datetime | timestamp ) $/x) { + $info->{_ic_dt_method} = $data_type; + } + else { + $info->{_ic_dt_method} = $requested_type; } - return unless ($type eq 'datetime' || $type eq 'date' || $type eq 'timestamp'); + return unless $info->{_ic_dt_method}; if ($info->{extra}) { for my $slot (qw/timezone locale floating_tz_ok/) { diff --git a/t/inflate/datetime_pg.t b/t/inflate/datetime_pg.t index d39496f..62eb810 100644 --- a/t/inflate/datetime_pg.t +++ b/t/inflate/datetime_pg.t @@ -2,6 +2,7 @@ use strict; use warnings; use Test::More; +use Test::Warn; use lib qw(t/lib); use DBICTest; @@ -15,7 +16,7 @@ plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missin my $schema = DBICTest->init_schema(); -{ +warnings_are { my $event = $schema->resultset("EventTZPg")->find(1); $event->update({created_on => '2009-01-15 17:00:00+00'}); $event->discard_changes; @@ -33,6 +34,6 @@ my $schema = DBICTest->init_schema(); is($event->ts_without_tz, $dt, 'timestamp without time zone inflation'); is($event->ts_without_tz->microsecond, $dt->microsecond, 'timestamp without time zone microseconds survived'); -} +} [], 'No warnings during DT manipulations'; done_testing; diff --git a/t/lib/DBICTest/Schema/EventTZPg.pm b/t/lib/DBICTest/Schema/EventTZPg.pm index 444fe69..521a9c4 100644 --- a/t/lib/DBICTest/Schema/EventTZPg.pm +++ b/t/lib/DBICTest/Schema/EventTZPg.pm @@ -22,4 +22,9 @@ sub _datetime_parser { DateTime::Format::Pg->new(); } +# this is for a reentrancy test, the duplication from above is intentional +__PACKAGE__->add_columns( + ts_without_tz => { data_type => 'timestamp without time zone', inflate_datetime => 1 }, +); + 1;