From 4a3ee87eaf9c3fbd4bebfdc2759c0d83e88b7217 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 25 Mar 2021 09:53:13 -0300 Subject: [PATCH] Bug 28031: Avoid wrong exception on saving updated attribute In the case a non-repeatable attribute for a patron is being updated (its value) the routines that check the type is repeatable should exclude its own id from the search for things to work. This patch solves that. To test: 1. Apply the regression tests patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Patron/Attribute.t => FAIL: Tests explode! An unexpected exception is thrown! 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! 5. Sign off :-D --- Koha/Patron/Attribute.pm | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Koha/Patron/Attribute.pm b/Koha/Patron/Attribute.pm index 26fffeb7886..e453a4328a6 100644 --- a/Koha/Patron/Attribute.pm +++ b/Koha/Patron/Attribute.pm @@ -146,13 +146,16 @@ sub _check_repeatable { my $self = shift; if ( !$self->type->repeatable ) { - my $attr_count = Koha::Patron::Attributes->search( - { borrowernumber => $self->borrowernumber, - code => $self->code - } - )->count; + my $params = { + borrowernumber => $self->borrowernumber, + code => $self->code + }; + + $params->{id} = { '!=' => $self->id } + if $self->in_storage; + Koha::Exceptions::Patron::Attribute::NonRepeatable->throw( attribute => $self ) - if $attr_count > 0; + if Koha::Patron::Attributes->search($params)->count > 0; } return $self; -- 2.31.0