From 3cf9c44e396ff6e0512aa5cafd759e98babb2a54 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 1 Dec 2015 10:13:52 +0000 Subject: [PATCH] Bug 15270: Make Koha::Objects->find return undef instead of crashing On 3.20.05, if AnonymousPatron is set to a nonexistent borrowernumber, the about.pl crashes with DBIC result type isn't of the type Borrower at /home/koha/src/Koha/Objects.pm line 87. This was fixed on master by commit 6882949b1b3bd1284e3d2877244a64edee3883ca Date: Wed Apr 8 06:38:34 2015 -0400 Bug 13967 - System preferences need a package Test plan: Set the AnonymousPatron pref to a nonexistent borrowernumber Go on about.pl Without this patch, you get the error. --- Koha/Objects.pm | 2 ++ t/db_dependent/Objects.t | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 t/db_dependent/Objects.t diff --git a/Koha/Objects.pm b/Koha/Objects.pm index f347157..8ef6390 100644 --- a/Koha/Objects.pm +++ b/Koha/Objects.pm @@ -84,6 +84,8 @@ sub find { my $result = $self->_resultset()->find($id); + return unless $result; + my $object = $self->object_class()->_new_from_dbic( $result ); return $object; diff --git a/t/db_dependent/Objects.t b/t/db_dependent/Objects.t new file mode 100644 index 0000000..ab86a13 --- /dev/null +++ b/t/db_dependent/Objects.t @@ -0,0 +1,29 @@ +#!/usr/bin/perl + +# 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 . + +use Modern::Perl; + +use Test::More tests => 2; +use t::lib::TestBuilder; +use Koha::Database; +use Koha::Borrowers; +my $builder = t::lib::TestBuilder->new; + +my $patron = $builder->build( { source => 'Borrower' } ); +is( Koha::Borrowers->find( $patron->{borrowernumber} )->delete, 1, 'The patron has correctly been deleted' ); + +is( Koha::Borrowers->find( $patron->{borrowernumber} ), undef, 'Koha::Objects->find should not crash if the object does not exist' ); -- 2.1.0