[Koha-bugs] [Bug 25040] Problematic current_timestamp syntax generated by DBIx::Class::Schema::Loader

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Thu Apr 2 11:22:06 CEST 2020


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25040

--- Comment #1 from Jonathan Druart <jonathan.druart at bugs.koha-community.org> ---
Created attachment 102277
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=102277&action=edit
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

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list