From 3533aacef8772d43a471b558c4ae581b63a90ee7 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 31 Mar 2020 15:58:21 +0200 Subject: [PATCH] Bug 22001: Set unsafe only if RaiseError is not set Sooooo.... That was tricky, and the solution looks trivial. However it's not. We have unsafe set for "historical reason". Having it on when RaiseError is on have the effect of overwritting the DBIC error handler. The problem is: t/db_dependent/Circulation/MarkIssueReturned.t (and other tests) is failing with: # expecting: Koha::Exceptions::Object::BadValue # found: DBIx::Class::Exception ({UNKNOWN}: Can't locate object method "rethrow" via package "DBD::mysql::st execute failed: Incorrect datetime value: 'bad_date' for column 'returndate' at row 1 [for Statement "UPDATE `issues` SET `returndate` = ? WHERE ( `issue_id` = ? )" with ParamValues: 0='bad_date', 1=238] at /usr/share/perl5/DBIx/Class/Storage/DBI.pm line In Koha::Object->store, the exception is not a DBIx::Class::Exception object (as we except), but a string (on which we cannot call rethrow). Swithing unsafe off restores the expected behavior. To make sure the UI will not be affected, it is only turned off when RaiseError is set. The situation is still wrong (for UI), from the POD https://metacpan.org/pod/DBIx::Class::Storage::DBI (/unsafe) """ Note that your custom settings can cause Storage to malfunction, especially if you set a HandleError handler that suppresses exceptions and/or disable RaiseError. """ And also https://metacpan.org/release/DBIx-Class/source/lib/DBIx/Class/Storage/DBI.pm#L1531 Many thanks Tomas for the digging exploration! We need to turn RaiseError and remove the unsafe flag, for UI as well, but that should be done at the beginning of a dev cycle. Signed-off-by: Martin Renvoize --- Koha/Database.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Koha/Database.pm b/Koha/Database.pm index 6d8a1e2556..55baf80537 100644 --- a/Koha/Database.pm +++ b/Koha/Database.pm @@ -103,7 +103,7 @@ sub _new_schema { %encoding_attr, RaiseError => $RaiseError, PrintError => 1, - unsafe => 1, + unsafe => !$RaiseError, quote_names => 1, on_connect_do => [ $encoding_query || (), -- 2.39.5