From 99dc9ea0b06148b813d5e23398d8457c02636c0b Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 23 Jul 2021 00:39:16 -0300 Subject: [PATCH] Bug 28744: Better handling of undefined to_api_mapping We always had some mapping because of the DB vs. API object definition discrepancies. But bug 25260 revamps the reserves table, and it is a perfect match. It highlights this edge case: if no mapping defined, then and undef from_api_mapping is generated (as opposed to an empty hashref) and this leads to errors in the query translation from the API. This patch makes a small change so this method always returns an empty hashref. To test: 1. Apply the regression tests 2. Run: $ kshell k$ prove t/db_dependent/Koha/Object.t => FAIL: Test fail! 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! 5. Sign off :-D Signed-off-by: Tomas Cohen Arazi Signed-off-by: David Nind --- Koha/Object.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Koha/Object.pm b/Koha/Object.pm index 08602da67f..6f55c3b486 100644 --- a/Koha/Object.pm +++ b/Koha/Object.pm @@ -638,7 +638,8 @@ sub from_api_mapping { my $to_api_mapping = $self->to_api_mapping; - unless ( $self->{_from_api_mapping} ) { + unless ( defined $self->{_from_api_mapping} ) { + $self->{_from_api_mapping} = {}; while (my ($key, $value) = each %{ $to_api_mapping } ) { $self->{_from_api_mapping}->{$value} = $key if defined $value; -- 2.20.1