Koha Solutions knowledge base: run log of a live check Article https://kohasolutions.com/knowledge-base/koha-items-table-500-error Check scripts/kb/live/koha-items-table-500-error.mjs (SHA-256 71f82edfe1071cfec9183a0245ff3e45034bffeddc5deb1c1e88cf014259d0f0) Ran 2026-11-08T06:21:00Z (UTC), 92 s Koha 26.05.05 (Koha::version 26.05.05.000, database version 26.0505000) Source https://git.koha-community.org/Koha-community/Koha/src/commit/d3fc229bc5eaea25dfe88f86149386408fe5d32d System Ubuntu 24.04.5 LTS Setup A fresh Ubuntu 24.04 server with Koha installed from the Koha repository as our installation guide leaves it, reached over SSH: every command run as the sudo user librarian. Result PASS: all 8 claims held Each claim is something the article says. "seen" is what the check read back when it is not just a yes/no. Changes the check made to the test server were undone afterwards, as its header describes. == Claims == ok the server box starts with Koha installed ok set-up: one record with two items, A with no libraries, B with no holding library seen: BN=1 A=1 B=2 ok the items table's own request answers 500 {"error":"Something went wrong, check Koha logs for details.","error_code":"internal_server_error"} seen: 500 {"error":"Something went wrong, check Koha logs for details.","error_code":"internal_server_error"} ok sudo tail -n 0 -f: the two file headers, then under plack-api-error.log "[date] [ERROR] GET /api/v1/biblios//items: unhandled exception (Mojo::Exception)<>" seen: ==> /var/log/koha/library/plack-api-error.log <== ==> /var/log/koha/library/api-error.log <== ==> /var/log/koha/library/plack-api-error.log <== [2026/11/08 06:21:52] [ERROR] GET /api/v1/biblios/1/items: unhandled exception (Mojo::Exception)<> ok nothing in api-error.log for it (the log is plack-api-error.log) ok the same call without home_library/holding_library in the embed answers 200 ok search_for_data_inconsistencies.pl: "== Not defined items.homebranch and/or items.holdingbranch ==", item A "does not have home and holding library defined", item B "does not have a holding library defined", then "=> Edit these items and set valid homebranch and/or holdingbranch" seen: == Not defined items.homebranch and/or items.holdingbranch == * Item with itemnumber=1 does not have home and holding library defined * Item with itemnumber=2 does not have a holding library defined => Edit these items and set valid homebranch and/or holdingbranch ok the SQL (two lines joined by a backslash), on a terminal → a boxed table with the two items, NULL where the library is missing seen: +------------+--------------+---------+------------+---------------+ | itemnumber | biblionumber | barcode | homebranch | holdingbranch | +------------+--------------+---------+------------+---------------+ | 1 | 1 | KB-0001 | NULL | NULL | | 2 | 1 | KB-0002 | MAIN | NULL | +------------+--------------+---------+------------+---------------+ == The check that produced this log (scripts/kb/live/koha-items-table-500-error.mjs) == /** * Live check for prisma/ks-kb/24-koha-items-table-500-error.ts, on a real server since 2026-11-08 (plan212). * * A fresh Ubuntu 24.04 server with Koha installed as the installation guide leaves it (box.mjs ensureKohaImage), * reached over SSH as the sudo user `librarian`. Set-up (not shown in the article): one record with two items, the way * an import without 952$a/$b leaves them, item A with no home and no holding library, item B with no holding library. * Then, as a reader does: the API log is watched with the article's `tail -n 0 -f` while the holdings table's own * request is made (the staff items API with catalogue_detail.inc's embed list, from a staff session logged in with * curl), search_for_data_inconsistencies.pl and the SQL query. The box is removed at the end. ~2 minutes. */ import { createBox, ensureKohaImage, KOHA_IMAGE, removeBox, ssh, staffPassword } from './server-box/box.mjs' /** liveKoha: false — runs only on its own server box, so kb:verify neither starts nor reads live Koha. */ export const meta = { koha: '26.05.05', passed: '2026-11-08', liveKoha: false } const EMBED = '+strings,_status,home_library,holding_library,checkout,checkout.patron,transfer,transfer+strings,first_hold,first_hold+strings,first_hold.patron,first_hold.desk' const LOG = '/var/log/koha/library' const STAFF = 'http://localhost:8080' const HOST_HDR = '-H "Host: library-intra.example.org"' export default async function run(ctx) { const err = ensureKohaImage() ?? createBox({ image: KOHA_IMAGE }) ctx.check('the server box starts with Koha installed', err === null, err ?? '') if (err) return try { await body(ctx) } finally { removeBox() } } async function body(ctx) { const L = (cmd) => ssh('librarian', cmd).replace(/\s+$/, '') const b64 = (s) => Buffer.from(s).toString('base64') await new Promise((r) => setTimeout(r, 10000)) // services coming up after boot // Set-up: the record and its two broken items (Koha's own API, as an import would make them, then the branches cleared). const fixture = `use Modern::Perl; use C4::Biblio; use MARC::Record; use MARC::Field; use Koha::Item; use C4::Context; my $r = MARC::Record->new; $r->append_fields(MARC::Field->new('245', '1', '0', a => 'Imported without item libraries')); my ($bn) = C4::Biblio::AddBiblio($r, ''); my @i = map { Koha::Item->new({ biblionumber => $bn, homebranch => 'MAIN', holdingbranch => 'MAIN', itype => 'BK', barcode => "KB-000$_" })->store->itemnumber } 1, 2; my $dbh = C4::Context->dbh; $dbh->do('UPDATE items SET homebranch = NULL, holdingbranch = NULL WHERE itemnumber = ?', undef, $i[0]); $dbh->do('UPDATE items SET holdingbranch = NULL WHERE itemnumber = ?', undef, $i[1]); print "BN=$bn A=$i[0] B=$i[1]\\n";` const made = L(`echo ${b64(fixture)} | base64 -d > /tmp/kbv.pl && chmod 644 /tmp/kbv.pl && sudo koha-shell library -c "perl /tmp/kbv.pl"; rm -f /tmp/kbv.pl`) const [, bn, a, b] = /BN=(\d+) A=(\d+) B=(\d+)/.exec(made) ?? [] ctx.check('set-up: one record with two items, A with no libraries, B with no holding library', Boolean(bn), made.slice(-200)) if (!bn) return // A staff session, as the browser has when it loads the record (the password is passed, never shown). const pw = staffPassword() L(`J=/tmp/kbv24j; rm -f $J; curl -s -c $J -b $J ${HOST_HDR} ${STAFF}/cgi-bin/koha/mainpage.pl -o /tmp/kbv24l.html T=$(grep -o 'name="csrf_token" value="[^"]*"' /tmp/kbv24l.html | head -1 | sed 's/.*value="//;s/"//') curl -s -c $J -b $J ${HOST_HDR} -d "login_userid=koha&login_op=cud-login&koha_login_context=intranet" --data-urlencode "login_password=${pw}" --data-urlencode "csrf_token=$T" ${STAFF}/cgi-bin/koha/mainpage.pl -o /dev/null`) const api = (embed) => L(`curl -s -c /tmp/kbv24j -b /tmp/kbv24j ${HOST_HDR} -H "Accept: application/json" ${embed ? `-H "x-koha-embed: ${embed}"` : ''} -o /tmp/kbv24.json -w '%{http_code}' "${STAFF}/api/v1/biblios/${bn}/items?_page=1&_per_page=20"; echo; cat /tmp/kbv24.json`) // The article's tail, running while the table's request is made. // setsid nohup: a plain background job is killed by the hang-up when this SSH session closes (the first server run) L(`sudo setsid nohup timeout 20 stdbuf -oL tail -n 0 -f ${LOG}/plack-api-error.log ${LOG}/api-error.log > /tmp/kbv24.tail 2>&1 < /dev/null & sleep 2`) const bad = api(EMBED) await new Promise((r) => setTimeout(r, 15000)) const tail = L('cat /tmp/kbv24.tail') ctx.check('the items table\'s own request answers 500 {"error":"Something went wrong, check Koha logs for details.","error_code":"internal_server_error"}', bad === '500\n{"error":"Something went wrong, check Koha logs for details.","error_code":"internal_server_error"}', bad.slice(0, 200)) ctx.check(`sudo tail -n 0 -f: the two file headers, then under plack-api-error.log "[date] [ERROR] GET /api/v1/biblios//items: unhandled exception (Mojo::Exception)<>"`, tail.startsWith(`==> ${LOG}/plack-api-error.log <==\n\n==> ${LOG}/api-error.log <==\n`) && new RegExp(`==> ${LOG}/plack-api-error\\.log <==\\n\\[\\d{4}/\\d\\d/\\d\\d \\d\\d:\\d\\d:\\d\\d\\] \\[ERROR\\] GET /api/v1/biblios/${bn}/items: unhandled exception \\(Mojo::Exception\\)<>`).test(tail), tail) ctx.check('nothing in api-error.log for it (the log is plack-api-error.log)', !/==> \S+\/api-error\.log <==\n\[/.test(tail)) ctx.check('the same call without home_library/holding_library in the embed answers 200', api('+strings').startsWith('200\n')) L('rm -f /tmp/kbv24*') // The two ways the article finds the items. const inc = L('sudo koha-shell -c "perl /usr/share/koha/bin/maintenance/search_for_data_inconsistencies.pl" library') ctx.check('search_for_data_inconsistencies.pl: "== Not defined items.homebranch and/or items.holdingbranch ==", item A "does not have home and holding library defined", item B "does not have a holding library defined", then "=> Edit these items and set valid homebranch and/or holdingbranch"', inc.includes(`== Not defined items.homebranch and/or items.holdingbranch ==\n\t* Item with itemnumber=${a} does not have home and holding library defined\n\t* Item with itemnumber=${b} does not have a holding library defined\n=> Edit these items and set valid homebranch and/or holdingbranch`), inc.slice(0, 500)) const q = L(`sudo koha-mysql library -e "SELECT itemnumber, biblionumber, barcode, homebranch, holdingbranch \\ FROM items WHERE homebranch IS NULL OR holdingbranch IS NULL;"`) // On a terminal the mysql client draws a boxed table (the first server run); tab-separated rows are its piped form. const row = (...c) => `| ${String(c[0]).padStart(10)} | ${String(c[1]).padStart(12)} | ${c[2].padEnd(7)} | ${c[3].padEnd(10)} | ${c[4].padEnd(13)} |` const rule = '+------------+--------------+---------+------------+---------------+' ctx.check('the SQL (two lines joined by a backslash), on a terminal → a boxed table with the two items, NULL where the library is missing', q === [rule, '| itemnumber | biblionumber | barcode | homebranch | holdingbranch |', rule, row(a, bn, 'KB-0001', 'NULL', 'NULL'), row(b, bn, 'KB-0002', 'MAIN', 'NULL'), rule].join('\n'), q) const env = L(`grep PRETTY_NAME /etc/os-release; perl -I/usr/share/koha/lib -MKoha -e 'print qq{KOHA=}, Koha::version, qq{\\n}'; sudo koha-mysql library -N -B -e "SELECT CONCAT('DB=', value) FROM systempreferences WHERE variable='Version'"`) ctx.ranIn({ osRelease: (env.match(/^PRETTY_NAME=.*$/m) ?? [''])[0], kohaVersion: (env.match(/^KOHA=(\S+)/m) ?? [])[1] ?? '', db: (env.match(/^DB=(\S+)/m) ?? [])[1] ?? '' }, 'A fresh Ubuntu 24.04 server with Koha installed from the Koha repository as our installation guide leaves it, reached over SSH: every command run as the sudo user librarian.') }