Bug 33982

Summary: Error 500 on OPAC on recently edited records
Product: Koha Reporter: José Anjos <joseanjos>
Component: SearchingAssignee: Bugs List <koha-bugs>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: normal    
Priority: P5 - low CC: synapse.ova
Version: 22.11   
Hardware: All   
OS: Linux   
GIT URL: Initiative type: ---
Sponsorship status: --- Comma delimited list of Sponsors:
Crowdfunding goal: 0 Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:

Description José Anjos 2023-06-12 10:15:26 UTC
Since I update from version 22.05 to 22.11, every record I edit on Staff interface, can't be searched anymore on OPAC. (ERROR 500)
I've updated to 23.05 but the problem persists.
On Staff interface I can search it.

opac-error.log:
[Mon Jun 12 10:25:29.952048 2023] [cgi:error] [pid 6040] [client XX.XX.XX.XX:48968] AH01215: Use of uninitialized value in hash element at /usr/share/koha/opac/cgi-bin/opac/opac-detail.pl line 678.: /usr/share/koha/opac/cgi-bin/opac/opac-detail.pl
[Mon Jun 12 10:25:29.952589 2023] [cgi:error] [pid 6040] [client XX.XX.XX.XX:48968] AH01215: DBIC result _type  isn't of the _type Branch at /usr/share/koha/opac/cgi-bin/opac/opac-detail.pl line 678.: /usr/share/koha/opac/cgi-bin/opac/opac-detail.pl
[Mon Jun 12 10:25:29.987521 2023] [cgi:error] [pid 6040] [client XX.XX.XX.XX:48968] End of script output before headers: opac-detail.pl

I've checked for permissions issues but everything looks OK.
Rebuild Zebra: koha-rebuild-zebra -b -f -v koha  looks OK, no errors
Comment 1 José Anjos 2023-06-12 13:10:06 UTC
If I delete all Items, the search in OPAC works.
If I add the Item, the error 500 come again.
Comment 2 José Anjos 2023-06-12 14:24:05 UTC
After some more tests...
The problem is the field:
995$o	Circulation type (not for loan)	items.notforloan
connected to Authorized values for category: NOT_LOAN

I have to edit the Item, clean the field and save. Then the search on OPAC is OK.
Comment 3 Katrin Fischer 2023-06-12 17:09:24 UTC
Your items are missing mandatory fields. You need to make sure that all of these are set in all your items:

952$a items.homebranch
952$b items.holdingbranch
952$y items.itype

Koha won't function correctly if any of these are missing.
Comment 4 Katrin Fischer 2023-06-12 17:10:50 UTC
Hm if you are UNIMARC other MARC fields apply (missed that you wrote you have 995)

If you edit an item, you might not see if the field is empty (defaults might apply). Better probably to double check using SQL/reports.

This points to an issue with the branch:

AH01215: DBIC result _type  isn't of the _type Branch at /usr/share/koha/opac/cgi-bin/opac/opac-detail.pl line 678.: /usr/share/koha/opac/cgi-bin/opac/opac-detail.pl
Comment 5 José Anjos 2023-06-13 13:11:52 UTC
 Katrin Fischer, thank you for your help.
It seams that was missing Holding Branch on that Items.
Its strange because if I edited any record and just save it, without doing any change, that Item would give a Error 500 on OPAC search.
Now (maybe since 23.05 or restart) that problem stopped.
Comment 6 Oleg Vasylenko 2024-02-21 14:54:49 UTC
Our library had same problem after upgrading to Koha 23.05. Thank you for pointing the reason for such a problem.

-- Diagnosing the problem --
Run SQL queries:
SELECT holdingbranch, count(*) FROM items GROUP BY holdingbranch;
SELECT homebranch, count(*) FROM items GROUP BY homebranch;
 — there should be no NULL records

-- Solving the problem --
If you have just one library it is easy to solve the problem with the following SQL queries (change LIBCODE with your library code):
UPDATE items SET homebranch = "LIBCODE" WHERE homebranch IS NULL;
UPDATE items SET holdingbranch = "LIBCODE" WHERE holdingbranch IS NULL;

-- Securing from future problems --
Edit MARC frameworks and make subfields with Koha connection items.homebranch, items.holdingbranch, items.itype mandatory.
Subfields for MARC21 are provided above. For UNIMARC these are probably 995$b, 995$c, 995$r (at least in our case)


Similar queries could be added to Koha health check to show possible problems in DB