Bugzilla – Attachment 127924 Details for
Bug 29387
BatchUpdateBiblio does not handle exception correctly
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29387: [21.05] Stringify exception when logging error during a batch mod biblio
Bug-29387-2105-Stringify-exception-when-logging-er.patch (text/plain), 5.99 KB, created by
Jonathan Druart
on 2021-11-22 10:53:47 UTC
(
hide
)
Description:
Bug 29387: [21.05] Stringify exception when logging error during a batch mod biblio
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2021-11-22 10:53:47 UTC
Size:
5.99 KB
patch
obsolete
>From fa36814f4e3058c08fc4e839f7c8392aafd4bb7e Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 22 Nov 2021 11:52:52 +0100 >Subject: [PATCH] Bug 29387: [21.05] Stringify exception when logging error > during a batch mod biblio >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >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> > >Bug 29387: Stringify exceptions for other background job modules > >Signed-off-by: Joonas Kylmälä <joonas.kylmala@iki.fi> > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> > >Bug 29387: (QA follow-up) Fix modules in test > >Can't locate object method "new" via package "Koha::BackgroundJob::BatchUpdateBiblio" (perhaps you forgot to load "Koha::BackgroundJob::BatchUpdateBiblio"?) at t/db_dependent/Koha/BackgroundJobs/BatchUpdateBiblio.t line 45. > >How did it pass at signoff? > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > Koha/BackgroundJob/BatchUpdateAuthority.pm | 2 +- > Koha/BackgroundJob/BatchUpdateBiblio.pm | 2 +- > .../Koha/BackgroundJobs/BatchUpdateBiblio.t | 74 +++++++++++++++++++ > 3 files changed, 76 insertions(+), 2 deletions(-) > create mode 100755 t/db_dependent/Koha/BackgroundJobs/BatchUpdateBiblio.t > >diff --git a/Koha/BackgroundJob/BatchUpdateAuthority.pm b/Koha/BackgroundJob/BatchUpdateAuthority.pm >index 24f1e9a4000..1e985e2989d 100644 >--- a/Koha/BackgroundJob/BatchUpdateAuthority.pm >+++ b/Koha/BackgroundJob/BatchUpdateAuthority.pm >@@ -90,7 +90,7 @@ sub process { > type => 'error', > code => 'authority_not_modified', > authid => $authid, >- error => ($@ ? $@ : 0), >+ error => ($@ ? "$@" : 0), > }; > } else { > push @messages, { >diff --git a/Koha/BackgroundJob/BatchUpdateBiblio.pm b/Koha/BackgroundJob/BatchUpdateBiblio.pm >index 7cb7969474d..9e4346a870d 100644 >--- a/Koha/BackgroundJob/BatchUpdateBiblio.pm >+++ b/Koha/BackgroundJob/BatchUpdateBiblio.pm >@@ -95,7 +95,7 @@ sub process { > type => 'error', > code => 'biblio_not_modified', > biblionumber => $biblionumber, >- error => ($@ ? $@ : $error), >+ error => ($@ ? "$@" : $error), > }; > } else { > push @messages, { >diff --git a/t/db_dependent/Koha/BackgroundJobs/BatchUpdateBiblio.t b/t/db_dependent/Koha/BackgroundJobs/BatchUpdateBiblio.t >new file mode 100755 >index 00000000000..8463aef6e10 >--- /dev/null >+++ b/t/db_dependent/Koha/BackgroundJobs/BatchUpdateBiblio.t >@@ -0,0 +1,74 @@ >+#!/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 Koha::BackgroundJob::BatchUpdateBiblio; >+use Koha::Exceptions::Exception; >+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; >+}; >-- >2.25.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29387
:
127205
|
127207
|
127431
|
127594
|
127595
|
127825
|
127826
|
127827
| 127924