Bug 40777 - 500 Error: Something went wrong when loading the table Should Exit Cleanly
Summary: 500 Error: Something went wrong when loading the table Should Exit Cleanly
Status: In Discussion
Alias: None
Product: Koha
Classification: Unclassified
Component: Cataloging (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low normal
Assignee: Jonathan Druart
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-09-09 15:53 UTC by John Yorio
Modified: 2025-10-09 10:40 UTC (History)
7 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
Bug 40777: Introduce Koha::Database::DataInconsistency (3.62 KB, patch)
2025-10-07 14:18 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 40777: Add 'Audit' button in the toolbar (3.22 KB, patch)
2025-10-07 14:18 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 40777: Add info in the alert (1.86 KB, patch)
2025-10-07 14:18 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 John Yorio 2025-09-09 15:53:59 UTC
It's possible this is related to/a duplicate of https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40762 but I am not certain.

In Koha 24.05 and 24.11, in the staff interface, if a bib with an item without a 952$a and 952$b is imported, when the staff member then goes to the bib record they receive a modal pop-up stating "Something went wrong when loading the table. 500: error". 

If they click OK on that message, a processing box sits on the screen (you can see the bib loaded behind it) and spins. 

The console log shows:
datatables_24.1107000.js: 408
DataTables warning: table id=holdings_table - Ajax error. For more information about this error, please see https://datatables.net/tn/7

The "processing" box is not modal and it is possible to click on Edit, Manage items, and then edit the problem item to add the missing Home and Current libraries and resolve the cause of the error.

This behavior does not occur in 23.11. 

While, of course, the item needs the Home and Current library, the error alert is a change in expected behavior from staff member perspective. A cleaner exit with a more informative message than a 500 error seems preferable.
Comment 1 Jonathan Druart 2025-10-07 14:18:18 UTC
Created attachment 187526 [details] [review]
Bug 40777: Introduce Koha::Database::DataInconsistency
Comment 2 Jonathan Druart 2025-10-07 14:18:20 UTC
Created attachment 187527 [details] [review]
Bug 40777: Add 'Audit' button in the toolbar
Comment 3 Jonathan Druart 2025-10-07 14:18:22 UTC
Created attachment 187528 [details] [review]
Bug 40777: Add info in the alert
Comment 4 Jonathan Druart 2025-10-07 14:21:05 UTC
Patches for discussion and feedback.

I am suggesting to move the code from the search_for_inconsistencies.pl maintenance script to a module to make it reusable from the Koha UI.

Those patch moves only the first check (no valid home or holding library) to the module, and add an "Audit" icon to the bibliographic toolbar.

https://snipboard.io/1owIgH.jpg

If people are willing to test and provide feedback, I will provide more work.
Comment 5 Marcel de Rooy 2025-10-07 14:55:48 UTC
From kohastructure
  `homebranch` varchar(10) DEFAULT NULL COMMENT 'foreign key from the branches table for the library that owns this item (MARC21 952$a)',
  `holdingbranch` varchar(10) DEFAULT NULL COMMENT 'foreign key from the branches table for the library that is currently in possession item (MARC21 952$b)',

While both columns may still be NULL, we will have such issues.
What about NOT NULL to ensure integrity?
If we create an item somewhere or import it, we should probably know where it belongs. Just suspecting that invalid branchcodes during import may be at stake.

And note that the REST API who is called to fetch the items, may need some extra check while we dont address it in the table design?
Comment 6 Jonathan Druart 2025-10-09 10:40:19 UTC
(In reply to Marcel de Rooy from comment #5)
> From kohastructure
>   `homebranch` varchar(10) DEFAULT NULL COMMENT 'foreign key from the
> branches table for the library that owns this item (MARC21 952$a)',
>   `holdingbranch` varchar(10) DEFAULT NULL COMMENT 'foreign key from the
> branches table for the library that is currently in possession item (MARC21
> 952$b)',
> 
> While both columns may still be NULL, we will have such issues.
> What about NOT NULL to ensure integrity?
> If we create an item somewhere or import it, we should probably know where
> it belongs. Just suspecting that invalid branchcodes during import may be at
> stake.
> 
> And note that the REST API who is called to fetch the items, may need some
> extra check while we dont address it in the table design?

This is outside the scope.

I have implemented the first test of misc/maintenance/search_for_data_inconsistencies.pl, but there are more:

* incorrect item type (yes you could argue that a FK is missing as well for this one)
* invalid marcxml
* item fields in MARC
* wrong authorised values
* record without title

The goal here is to offer the output of the script from the UI.