From 9a6fb1f1b063ec0cfcd6c94ff006bdbc1a19d80b Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 4 Mar 2021 08:24:54 -0300 Subject: [PATCH] Bug 27858: Make Koha::Patron::Attribute->store raise an exception on invalid type/code This patch adds type validation to the ->store method. And exception should be thrown if the type is invalid. Things currently explode in such situations, so this doesn't change the behavior (just adding more informative failure information). To test: 1. Apply the previous patches 2. Run: $ kshell k$ prove t/db_dependent/Koha/Patron/Attribute.t => FAIL: No exception is thrown on the bad case, weird error 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! Exception thrown! 5. Sign off :-D --- Koha/Patron/Attribute.pm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Koha/Patron/Attribute.pm b/Koha/Patron/Attribute.pm index dc97aa8cc93..26fffeb7886 100644 --- a/Koha/Patron/Attribute.pm +++ b/Koha/Patron/Attribute.pm @@ -46,6 +46,9 @@ sub store { my $self = shift; + Koha::Exceptions::Patron::Attribute::InvalidType->throw( type => $self->code ) + unless Koha::Patron::Attribute::Types->find( $self->code ); + $self->_check_repeatable; $self->check_unique_id; -- 2.30.1