Bug 22001: Set unsafe only if RaiseError is not set
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 31 Mar 2020 13:58:21 +0000 (15:58 +0200)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 31 Mar 2020 14:17:23 +0000 (15:17 +0100)
commit3533aacef8772d43a471b558c4ae581b63a90ee7
tree788bd27539699ea510825293ad965827863a2f5c
parent9c383aa286fee5a29c6f084873f2eb6644bad64f
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 <martin.renvoize@ptfs-europe.com>
Koha/Database.pm