Go to file
Tomas Cohen Arazi 38460cbd40
Bug 35246: Make Koha::Biblio->to_api throw relevant exception if no biblioitem row
This patch makes the `to_api()` method return an proper exception when
the `$self->biblioitem` accessor returns `undef`. This is a bad data
scenario and we could do better in terms of logging the situation.

The new exception will be correctly rendered in the logs by the
`unhandled_exception` Mojolicious helper and no behavior change on the
API.

I wasn't sure to keep the api tests I wrote. I originally added handling
for the specific exception in the controller, but it become obvious it
was not worth: too much code, the `GET /biblios` endpoint would need the
same treatment, etc. And the current `500 Internal server error` is good
enough as a response, and the logs explain the situation correctly.

To test:
1. On a fresh `KTD` pick a biblio (say biblionumber=1)
2. Use your favourite REST tool (Postman?) to access the record with
   `Accept: application/json`. i.e.

```
GET kohadev.localhost/api/v1/biblios/1
Accept: application/json
```

=> SUCCESS: All good
3. Delete the related `biblioitems` row:
   $ ktd --shell
  k$ koha-mysql kohadev
   > DELETE FROM biblioitems WHERE biblionumber=1; \q
4. Repeat 2
=> SUCCESS: You get a 500 error
5. Check the logs
=> FAIL: You get a cryptic message about accessing a method on an
undefined object:

```
2025/02/13 13:15:00] [ERROR] GET /api/v1/biblios: unhandled exception (Mojo::Exception)<<Can't call method "to_api" on an undefined value at /usr/share/koha/Koha/Biblio.pm line 1433.>>
```

6. Apply this patch
7. Restart things:
  k$ restart_all
8. Repeat 2
=> SUCCESS: You get a 500 error
9. Check the logs
=> SUCCESS: You get a more meaningful exception:

```
[2025/02/13 13:20:00] [ERROR] GET /api/v1/biblios/1: unhandled exception (Koha::Exceptions::RelatedObjectNotFound)<<Exception 'Koha::Exceptions::RelatedObjectNotFound' thrown 'The requested related object does not exist' with accessor => biblioitem, class => Koha::Biblioitem>>
```

10. Run the tests:
  k$ prove t/db_dependent/Koha/Biblio.t \
           t/db_dependent/api/v1/biblios.t
=> SUCCESS: They pass!
11. Sign off :-D

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit 03ae61e9f8)
Signed-off-by: Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com>
2025-08-06 13:25:37 +00:00
C4 Bug 36008: Use notice_email_address instead of email for SendAlerts issue type 2025-08-06 09:56:59 +00:00
Koha Bug 35246: Make Koha::Biblio->to_api throw relevant exception if no biblioitem row 2025-08-06 13:25:37 +00:00
acqui Bug 39572: Improve EDIFACT order confirmation message 2025-07-31 15:48:37 +02:00
admin Bug 39878: EDIFACT vendor account records sets default port incorrectly for FTP 2025-08-04 10:21:57 +02:00
api Bug 39932: Make Koha::Item->_status return an arrayref 2025-08-01 10:24:28 +02:00
authorities Bug 36603: (QA follow-up) Resolve two conditional declarations 2024-11-08 16:42:53 +01:00
basket Bug 31224: Update instances of metadata->record 2024-11-07 16:29:23 +01:00
bin
…
bookings Bug 35574: Bookings tab from biblio details should only require manage_bookings permission 2023-12-18 15:21:04 +01:00
catalogue Bug 38846: Only call getLanguages for advanced search pages 2025-04-22 23:01:34 +02:00
cataloguing Bug 37305: Remove C4::Biblio::prepare_host_field 2025-07-28 10:55:22 +02:00
circ Bug 37650: (follow-up) Remove FIXME around CheckReserves call 2025-08-06 12:55:16 +00:00
clubs Bug 34478: Manual fix - add op clubs/templates-add-modify 2024-03-01 10:57:55 +01:00
course_reserves Bug 28762: Use Koha::Course in course-details controller 2024-07-23 16:04:05 +01:00
debian Bug 40304: Zebrasrv configs now work on ARM CPUs 2025-08-01 14:52:19 +02:00
docs Bug 40022: Add the 25.11 release team (squashed) 2025-07-25 16:39:02 +02:00
erm
…
errors Bug 37741: Do not send cookie back from error pages 2024-08-30 12:45:45 +02:00
etc Bug 39303: Add audience index to SRU 2025-08-04 15:02:17 +02:00
ill Bug 35570: Prevent use of ILL module if deprecated FreeForm backend is installed 2024-10-31 08:05:21 +01:00
installer Bug 38794: say_success only if updated 2025-08-06 09:56:58 +00:00
koha-tmpl Bug 39088: Correctly prefix url with protocol when OPACURLOpenInNewWindow on the OPAC result page 2025-08-06 13:23:48 +00:00
labels Bug 30745: (QA follow-up) tidy 2024-11-18 17:44:31 +01:00
lib Bug 35681: Use ::Bootstrap version of FromANSI 2024-05-02 16:47:39 +02:00
members Bug 40116: Do not display "Patron is already a guarantor..." popup when error occurs 2025-08-01 11:41:27 +02:00
misc Bug 38900: Provide info about the problematic strings 2025-08-06 09:57:02 +00:00
offline_circ Bug 34478: Changes for offline_circ 2024-03-01 10:58:34 +01:00
opac Bug 38963: Check for existence of biblio object before fetching cover images in the OPAC 2025-08-06 09:57:01 +00:00
patron_lists Bug 37266: [24.11.x] patron_lists/delete.pl should have CSRF protection 2025-02-24 19:30:42 +01:00
patroncards Bug 37614: Printing patron cards from patron lists should be a GET 2024-08-16 17:33:45 +02:00
plugins Bug 30897: Add option to disable automated restart 2024-04-11 16:53:42 +02:00
pos Bug 33478: Apply formatting to RECEIPT 2024-04-26 20:15:44 +02:00
preservation Bug 38089: (follow-up) More fixes for errors in original submission 2024-10-11 11:13:47 +02:00
recalls Bug 38089: (follow-up) More fixes for errors in original submission 2024-10-11 11:13:47 +02:00
reports Bug 40419: Fix wrong license 2025-08-01 14:50:29 +02:00
reserve Bug 37427: Fix club search to display all clubs when search field is empty, consistent with patron search behavior 2025-02-13 10:04:54 +01:00
reviews Bug 2486: Show user comments in staff interface 2024-08-26 17:39:42 +02:00
rotating_collections Bug 34478: Manual fix - add op - rotating_collections/addItems 2024-03-01 10:57:33 +01:00
serials Bug 34971: (QA follow-up) Op is now cud-reopen 2025-08-06 10:16:37 +00:00
services
…
skel
…
suggestion Bug 33484: Fix for suggestions 2024-10-28 17:10:26 +01:00
svc Bug 31224: Update instances of metadata->record 2024-11-07 16:29:23 +01:00
t Bug 35246: Unit tests 2025-08-06 13:25:36 +00:00
tags Bug 38969: (QA follow-up) fix tidy 2025-04-24 18:42:32 +02:00
tools Bug 39871: (QA follow-up) Do not hardcode nullable check 2025-07-28 10:09:52 +02:00
virtualshelves Bug 31224: Update instances of metadata->record 2024-11-07 16:29:23 +01:00
xt Bug 40419: Changes to testing logic 2025-08-01 14:50:29 +02:00
.editorconfig
…
.gitignore Bug 35402: Update the OPAC and staff interface to Bootstrap 5 2024-08-23 15:58:41 +02:00
.htaccess
…
.mailmap 24.11.00: Update .mailmap 2024-11-25 13:16:42 +01:00
.perlcriticrc
…
.perltidyrc
…
.prettierrc.js Bug 38546: Set tabWidth and useTabs in prettierrc 2025-08-06 09:56:52 +00:00
.proverc.dist
…
.stylelintrc.json
…
INSTALL
…
Koha.pm Increment version for 24.11.07 release 2025-07-24 22:13:30 +02:00
LICENSE
…
MANIFEST.SKIP
…
Makefile.PL Bug 38167: (QA follow-up) Remove old, add new eslint config to Makefile.PL 2025-08-06 09:57:05 +00:00
README
…
README.md
…
README.robots
…
about.pl Bug 38988: Make the polling use case be normal in about page 2025-08-06 12:48:52 +00:00
app.psgi Bug 36149: Add userenv middleware to app.psgi 2024-05-14 15:04:37 -03:00
build-resources.PL
…
changelanguage.pl
…
cpanfile Bug 39857: Add new dependency Test::NoWarnings for 24.11.x 2025-05-26 11:03:03 +02:00
cypress.config.ts Bug 36012: Extend cypress's requestTimeout value 2024-03-22 15:07:36 +01:00
eslint.config.mjs Bug 38167: Migrate ESLint config to new flat format 2025-08-06 09:57:04 +00:00
fix-perl-path.PL
…
gulpfile.js Bug 36640: (follow-up) CSS fixes for DataTables controls 2024-11-14 14:19:34 +01:00
help.pl
…
kohaversion.pl
…
mainpage.pl Bug 36064: (QA follow-up) Simplify and tidy 2024-10-25 11:09:51 +02:00
package.json Bug 38149: Add ESLint & prettier to package.json 2025-08-06 09:57:03 +00:00
rewrite-config.PL
…
rspack.config.js Bug 37824: (QA follow-up) Fix improper handling of jQuery and DataTables libraries by marking them as externals 2024-09-16 18:41:17 +02:00
tsconfig.json
…
webpack.config.js Bug 35919: Add record sources admin page 2024-04-26 17:06:04 +02:00
yarn.lock Bug 38503: Update yarn.lock 2025-04-22 23:01:53 +02:00

README.md

Koha is a free software integrated library system (ILS).

Koha is distributed under the GNU GPL version 3 or later.

Note: Koha does not accept pull requests from git hosting sites.

Note: This project has its own bug tracker, to report a bug or submit a patch visit http://bugs.koha-community.org.

For guidelines on submitting patches for Koha please visit https://wiki.koha-community.org/wiki/SubmitingAPatch

The developers handbook can be found at https://wiki.koha-community.org/wiki/Developer_handbook

http://koha-community.org/

Koha Logo