Catalyst::DBIC::SchemaでInflateColumn::DateTime
最近catalystアップデートされちゃって、予期せぬエラーとかで悩まされました。
Couldn't render template "undef error - DBIx::Class::InflateColumn::get_inflated_column(): Error while inflating 0000-00-00 for regist_date on MyApp::Schema::Result::Account: The 'month' parameter ("00") to DateTime::new did not pass the 'is between 1 and 12' callback at /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/DateTime.pm line 171 DateTime::new('undef', 'month', 00, 'day', 00, 'year', 0000) called at /usr/lib/perl5/site_perl/5.8.8/DateTime/Format/Builder/Parser/Regex.pm line 135
MySQLのregist_dateに月日が入っていて、値が0000-00-00の場合、エラーとなります。
__PACKAGE__->load_components("InflateColumn::DateTime", "Core");
Helperが作るDBIC::Schemaのload_componentsにInflateColumn::DateTimeが付いています。
確認したら
前のhelperが作るSchemaは
__PACKAGE__->load_components("Core");
でした。
DBIx::Class::InflateColumn::DateTimeはDBIx-Classに含まれるモジュールなんだけど、モジュール削除したりなにやらして元に戻そうとしてやらかしてしまったと。
以上やれやれなレポートでした。
と思っていましたが、
http://search.cpan.org/~ribasushi/DBIx-Class-0.08108/lib/DBIx/Class/InflateColumn/DateTime.pm
を見ると、
In the case of an invalid date, DateTime will throw an exception. To bypass these exceptions and just have the inflation return undef, use the datetime_undef_if_invalid option in the column info:
ということで
"broken_date", { data_type => "datetime", default_value => '0000-00-00', is_nullable => 1, datetime_undef_if_invalid => 1 }
のdatetime_undef_if_invalid => 1 これでundefな値でもスルーしてくれるようです。
上記エラーのあったregist_dateの部分にも追加したところ問題なく動作しましたよと。