From 1d6108206d1e4d459d08ee289582f1c017666aaf 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 Signed-off-by: Marcel de Rooy JD amended patch: remove uneeded commented lines Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall --- Koha/Object.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Koha/Object.pm b/Koha/Object.pm index 806d42d1aa..45f9c9ea4b 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.39.5