From d46b0c110653c55f9ccc3f284c3c0b1899bad133 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 14 Apr 2026 17:03:26 +0100 Subject: [PATCH] Bug 41728: (QA follow-up) Move data consistency check before blocker handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The data inconsistency die (checkout exists but patron does not) was placed after the blocker handling block. This meant that if an item had corrupt data AND triggered a blocker (e.g. withdrawn+blocked), the blocker handler would return early with patron as undef instead of dying on the inconsistency, silently masking database corruption. Move the check to immediately after extracting context from the availability result, before any blocker handling, matching the original AddReturn behavior where the die fired during checkout lookup. Signed-off-by: Tomás Cohen Arazi Signed-off-by: Martin Renvoize Signed-off-by: Pedro Amorim --- C4/Circulation.pm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 3f342a3412..3e735ba30a 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2444,6 +2444,16 @@ sub AddReturn { my $issue = $availability->context->{checkout}; $patron = $availability->context->{patron}; + # Data consistency check for issued items - must run before any blocker + # handling so that DB corruption is never masked by an early return + if ( $issue && !$patron ) { + die "Data inconsistency: barcode $barcode (itemnumber:" + . $item->itemnumber + . ") claims to be issued to non-existent borrowernumber '" + . $issue->borrowernumber . "'\n" + . Dumper( $issue->unblessed ) . "\n"; + } + # Set NotIssued message if item not checked out if ( !$issue ) { $messages->{'NotIssued'} = $barcode;