From: Peter Rabbitson Date: Fri, 3 Feb 2012 08:31:27 +0000 (+0100) Subject: Allow users to disable the "DT in search" warning introduced in e1038213 X-Git-Tag: v0.08197~115 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=07d6018a48520d6edfc5e2d97e8a07ef1fb20351;p=dbsrgits%2FDBIx-Class.git Allow users to disable the "DT in search" warning introduced in e1038213 --- diff --git a/Changes b/Changes index 18e68d0..654ccca 100644 --- a/Changes +++ b/Changes @@ -1,11 +1,13 @@ Revision history for DBIx::Class + * New Features / Changes + - Issue a warning when DateTime objects are passed to ->search + * Fixes - Fix SkipFirst and FirstSkip limit dialects (Informix and Firebird) * Misc - Codebase is now trailing-whitespace-free - - Issue a warning when DateTime objects are passed to ->search 0.08196 2011-11-29 05:35 (UTC) * Fixes diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 906ed97..95e8cae 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1465,13 +1465,18 @@ sub _gen_sql_bind { }]; } - if ($op eq 'select' - && first { blessed($_->[1]) && $_->[1]->isa('DateTime') } @final_bind) { + if ( + ! $ENV{DBIC_DT_SEARCH_OK} + and + $op eq 'select' + and + first { blessed($_->[1]) && $_->[1]->isa('DateTime') } @final_bind) { carp_unique 'DateTime objects passed to search() are not supported ' . 'properly (InflateColumn::DateTime formats and settings are not ' . 'respected.) See "Formatting DateTime objects in queries" in ' - . 'DBIx::Class::Manual::Cookbook'; + . 'DBIx::Class::Manual::Cookbook. To disable this warning for good ' + . 'set $ENV{DBIC_DT_SEARCH_OK} to true' } ($sql, \@final_bind); diff --git a/t/inflate/datetime.t b/t/inflate/datetime.t index 9fa7648..fe35c0e 100644 --- a/t/inflate/datetime.t +++ b/t/inflate/datetime.t @@ -7,6 +7,9 @@ use Try::Tiny; use lib qw(t/lib); use DBICTest; +# so user's env doesn't screw us +undef $ENV{DBIC_DT_SEARCH_OK}; + my $schema = DBICTest->init_schema(); plan skip_all => 'DT inflation tests need ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_dt_sqlite') @@ -21,13 +24,22 @@ isa_ok($event->starts_at, 'DateTime', 'DateTime returned'); my $starts = $event->starts_at; is("$starts", '2006-04-25T22:24:33', 'Correct date/time'); +my $dt_warn_re = qr/DateTime objects.+not supported properly/; + my $row; -warnings_exist { - $row = try { - $schema->resultset('Event')->search({ starts_at => $starts })->single +{ + local $ENV{DBIC_DT_SEARCH_OK} = 1; + local $SIG{__WARN__} = sub { + fail('Disabled warning still issued') if $_[0] =~ $dt_warn_re; + warn @_; }; -} [qr/DateTime objects.+not supported/], + $row = $schema->resultset('Event')->search({ starts_at => $starts })->single +} + +warnings_exist { + $row = $schema->resultset('Event')->search({ starts_at => $starts })->single +} [$dt_warn_re], 'using a DateTime object in ->search generates a warning'; TODO: { @@ -35,9 +47,7 @@ TODO: { is(eval { $row->id }, 1, 'DT in search'); - local $SIG{__WARN__} = sub { - warn @_ unless $_[0] =~ /DateTime objects.+not supported/; - }; + local $ENV{DBIC_DT_SEARCH_OK} = 1; ok($row = $schema->resultset('Event')->search({ starts_at => { '>=' => $starts } })