Bug 29387: Stringify exception when logging error during a batch mod biblio

If an exception is raised by one the methods/subroutines called when batch biblio update, the job will fail in the middle and some records won't be processed.

Test plan:
0. Don't apply the patch
In KTD you can run the a batch mod biblio on the 100 first records and
the worker will fail with
"""
countered object 'C4::Biblio::_koha_modify_biblioitem_nonmarc(): DBI Exception: DBD::mysql::st execute failed: Data too long for column 'lccn' at row 1 at /kohadevbox/koha/C4/Biblio.pm line 423
', but neither allow_blessed, convert_blessed nor allow_tags settings are enabled (or TO_JSON/FREEZE method missing) at /kohadevbox/koha/Koha/BackgroundJob/BatchUpdateBiblio.pm line 120.
"""
The UI is not saying anything about this problem.

Generate 100 biblionumbers: perl -e 'for (1..100){print "$_\n"}'
1. Apply the patch and confirm than now you see the detail of the batch
update and that biblionumber 72 is marked as not been modified with the
correct error (raw DBI error)

JK: add executable bit to BatchUpdateBiblio.t
Signed-off-by: Joonas Kylmälä <joonas.kylmala@iki.fi>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2021-11-02 10:43:57 +01:00
parent 62316cd585
commit 27793b8979
2 changed files with 73 additions and 1 deletions

View file

@ -100,7 +100,7 @@ sub process {
type => 'error',
code => 'biblio_not_modified',
biblionumber => $biblionumber,
error => ($@ ? $@ : $error),
error => ($@ ? "$@" : $error),
};
} else {
push @messages, {

View file

@ -0,0 +1,72 @@
#!/usr/bin/perl
# Copyright 2021 Koha Development team
#
# This file is part of Koha
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More tests => 1;
use Test::MockModule;
use JSON qw( encode_json decode_json );
use Koha::Database;
use Koha::BackgroundJobs;
use t::lib::TestBuilder;
my $schema = Koha::Database->new->schema;
my $builder = t::lib::TestBuilder->new;
subtest "Exceptions must be stringified" => sub {
plan tests => 1;
$schema->storage->txn_begin;
my $C4_biblio_module = Test::MockModule->new('C4::Biblio');
$C4_biblio_module->mock( 'ModBiblio',
sub { Koha::Exceptions::Exception->throw("It didn't work"); } );
my $biblio = $builder->build_sample_biblio;
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
my $job = Koha::BackgroundJob::BatchUpdateBiblio->new(
{
status => 'new',
size => 1,
borrowernumber => $patron->borrowernumber,
type => 'batch_biblio_record_modification',
data => encode_json {
record_ids => [ $biblio->biblionumber ],
}
}
)->store;
$job = Koha::BackgroundJobs->find( $job->id );
$job->process(
{ job_id => $job->id, record_ids => [ $biblio->biblionumber ] } );
my $data = decode_json $job->get_from_storage->data;
is_deeply(
$data->{messages}->[0],
{
biblionumber => $biblio->biblionumber,
code => 'biblio_not_modified',
error => "It didn't work",
type => "error"
}
);
$schema->storage->txn_rollback;
};