From 472dabbb60f9ea64f1a8d5b4a1bbbfdaebcd3118 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 2 Apr 2020 11:17:55 +0200 Subject: [PATCH] Bug 25040: Handle incorrect current_timestamp syntax There is an incorrect current_timestamp syntax generated by DBIx::Class::Schema::Loader Caught by the changes made to Koha::Object->store by bug 23463 (especially 9c383aa286fee5a29c6f084873f2eb6644bad64f) 154 elsif ( not defined $self->$col 155 && $columns_info->{$col}->{datetime_undef_if_invalid} ) 156 { 157 # timestamp 158 $self->_result()->set_column($col => $columns_info->{$col}->{default_value}); 159 } If a timestamp not null column does not have a value when store is called, the default value is set. The expected default value is \"current_timestamp"(`git grep current_timestamp Koha/Schema/Result`) but for some reasons DBIx::Class::Schema::Loader sometimes generates "current_timestamp()" (certainly depending on versions of DBIx::Class::Schema::Loader and DBMS MySQL vs MariaDB) It ends up with an error on insert/update: DBD::mysql::st execute failed: Incorrect datetime value: 'current_timestamp()' This should be a temporary patch, the root of the problem should be found and correct fixed. With this patch we want people to continue working with Koha until we investigate. Test plan: Apply this change: @ Koha/Schema/Result/Aqorder.pm:374 @ __PACKAGE__->add_columns( { data_type => "timestamp", datetime_undef_if_invalid => 1, - default_value => \"current_timestamp", + default_value => "current_timestamp()", is_nullable => 0, }, "rrp", and run: use Koha::Acquisition::Orders; use t::lib::TestBuilder; my $builder = t::lib::TestBuilder->new; my $order = $builder->build_object({ class => 'Koha::Acquisition::Orders' }); $order->timestamp(undef)->store; Without this patch you get an error --- Koha/Object.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Koha/Object.pm b/Koha/Object.pm index fde0fa9917..33f5e88492 100644 --- a/Koha/Object.pm +++ b/Koha/Object.pm @@ -155,7 +155,9 @@ sub store { && $columns_info->{$col}->{datetime_undef_if_invalid} ) { # timestamp - $self->_result()->set_column($col => $columns_info->{$col}->{default_value}); + my $default_value = $columns_info->{$col}->{default_value}; + $default_value = \"current_timestamp" if $default_value eq "current_timestamp()"; + $self->_result()->set_column($col => $default_value); } } } -- 2.20.1