From: Jason Stephenson Date: Tue, 7 Aug 2018 14:02:10 +0000 (-0400) Subject: LP 115706: Avoid Internal Server Errors with Hold Count Retrieval X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=09e3ffe09e6e56c9581c22ecd326471aa4ac24c1;p=working%2FEvergreen.git LP 115706: Avoid Internal Server Errors with Hold Count Retrieval It can happen that the query to get a record's hold count can run too long and timeout or fail for some other reason. When this happens, the user sees an Internal Server Error. The underlying cause is the following Perl error: Can't use an undefined value as an ARRAY reference at /usr/local/share/perl/5.22.1/OpenILS/Application/Circ/Holds.pm line 4264. This commit rearranges the code around that line to avoid this particular undefined value reference error. Signed-off-by: Jason Stephenson --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm index b15de7cf58..03fc6767f3 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm @@ -4268,8 +4268,17 @@ sub rec_hold_count { } if ($pld != $top_ou->id); } + # To avoid Internal Server Errors, we get an editor, then run the + # query and check the result. If anything fails, we'll return 0. + my $result = 0; + if (my $e = new_editor()) { + my $query_result = $e->json_query($query); + if ($query_result && @{$query_result}) { + $result = $query_result->[0]->{count} + } + } - return new_editor()->json_query($query)->[0]->{count}; + return $result; } # A helper function to calculate a hold's expiration time at a given