Bug 40324 - moremember.pl crashes when a barred patron doesn't have a borrower_debarments record
Summary: moremember.pl crashes when a barred patron doesn't have a borrower_debarments...
Status: In Discussion
Alias: None
Product: Koha
Classification: Unclassified
Component: Staff interface (show other bugs)
Version: 24.11
Hardware: PC Linux
: P5 - low minor
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-07-07 21:14 UTC by Joe Koop
Modified: 2025-10-10 08:04 UTC (History)
3 users (show)

See Also:
GIT URL:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Entire log. Is very short. (623 bytes, text/x-log)
2025-07-07 21:14 UTC, Joe Koop
Details
Bug 40324: Prevent 500 when no borrower_debarments for debarred patrons (1.67 KB, patch)
2025-10-10 08:02 UTC, Jonathan Druart
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Joe Koop 2025-07-07 21:14:22 UTC
Created attachment 183850 [details]
Entire log. Is very short.

(I've replaced my domain name(s) and hostname(s) with MY_DOMAIN below)

I click on the patron like normal in the table that shows which copy of the book is out to which patron, and I'm served a 500 error page.

The URL the link goes to is MY_DOMAIN/cgi-bin/koha/members/moremember.pl?borrowernumber=2518

I've attached the entirety of plack-error.log. The log file must've rotated recently.

Koha version:	24.11.04.000
OS version ('uname -a'):	Linux MY_DOMAIN 6.8.0-63-generic #66-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 13 20:25:30 UTC 2025 x86_64
Perl interpreter:	/usr/bin/perl
Perl version:	5.038002
MySQL version:	5.5.5-10.11.13-MariaDB-0ubuntu0.24.04.1
Apache version:	Server version: Apache/2.4.58 (Ubuntu)
PSGI:	Plack (deployment)
Memcached:	Servers: 127.0.0.1:11211 | Namespace: koha_koha | Status: running. | Config read from: koha-conf.xml
Zebra version:	Zebra 2.2.7 (C) 1994-2023, [...] SHA1 ID: ac40f289672405a299436d73c1532f9906774cc6 Using ICU
Zebra status:	Running
Message broker:	Using RabbitMQ
Date and time:	2025-07-07 04:09 PM
Time zone:	Used: America/Winnipeg | Config: America/Winnipeg | Environment (TZ): Undefined

Feel free to ask for more details.
Comment 1 Joe Koop 2025-07-08 14:38:54 UTC
I've done some more poking around.

  0 of my 2150 unrestricted patrons[1] have this issue.
257 of my  827   restricted patrons[2] have this issue.

-----

[1]: SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.surname, borrowers.firstname, borrowers.debarred, borrowers.debarredcomment FROM borrowers WHERE borrowers.debarred IS NULL AND NOT EXISTS ( SELECT 1 FROM borrower_debarments WHERE borrower_debarments.borrowernumber = borrowers.borrowernumber ) ORDER BY borrowers.cardnumber
[2]: SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.surname, borrowers.firstname, borrowers.debarred, borrowers.debarredcomment FROM borrowers WHERE borrowers.debarred IS NOT NULL OR EXISTS ( SELECT 1 FROM borrower_debarments WHERE borrower_debarments.borrowernumber = borrowers.borrowernumber ) ORDER BY borrowers.cardnumber
Comment 2 Joe Koop 2025-07-08 14:54:29 UTC
I've done even more poking around.

The patrons who are broken are missing a "borrower_debarments" record.

We have a custom script that wrangles patrons, syncing them with another system, and barring them if they don't exist in the other system. Our custom script must be misbehaving.

There is still an issue, however. Koha should handle missing "borrower_debarments" records, even if it's automatically adding a placeholder one, or doing something else.

I'm leaving this bug open.
Comment 3 Ray Delahunty 2025-10-07 06:22:52 UTC
We have 206 records in our 24.11.09 system that have this problem. It appears to happen where the debarred field is '9999-12-31' but where there is nothing in the debarredcomment. 

SELECT borrowernumber, debarred, debarredcomment
FROM borrowers
WHERE length(debarredcomment)=0
AND debarred='9999-12-31'
Comment 4 Jonathan Druart 2025-10-10 08:02:52 UTC
Created attachment 187717 [details] [review]
Bug 40324: Prevent 500 when no borrower_debarments for debarred patrons

There are reports of crash when viewing patron records that are debarred
but does not have a borrower_debarments entry.

We should know how those records have been created. It's data
inconsistency and I don't think we should deal with that in the code.
The DB structure is not really correct: we should not have
borrowers.debarred, but we kept it for historical reasons (and
reports).

This patch fixes the 500, but there are then other problems on the
screen:
Top of the screen:
" Account restricted since "

Under the "Restrictions (0)" tab:
"Patron is currently unrestricted."
Comment 5 Jonathan Druart 2025-10-10 08:04:40 UTC
https://chat.koha-community.org/koha-community/pl/g6978mah9f8dtgiycwnnpzmufr

I've attached a patch but I don't think it's a problem that should be fixed, it's an import problem it seems.

however we could:

Improve the import code (if the problem still exists in recent versions)
Add a data inconsistency check to catch this proble