Bug 35266 - opac-MARCdetail: Can't call method "metadata" on an undefined value
Summary: opac-MARCdetail: Can't call method "metadata" on an undefined value
Status: Pushed to stable
Alias: None
Product: Koha
Classification: Unclassified
Component: OPAC (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal (vote)
Assignee: Marcel de Rooy
QA Contact: Katrin Fischer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-11-06 13:15 UTC by Marcel de Rooy
Modified: 2023-11-17 07:05 UTC (History)
4 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Trivial patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
This fixes the display of the MARC view page when a record does not exist - it now redirects to the 404 (page not found) page. Previously, it generated an error trace, where the normal and ISBD view pages redirected to the 404 (page not found) page.
Version(s) released in:
23.11.00,23.05.06


Attachments
Bug 35266: Fix biblio check in opac-MARCdetail (1.11 KB, patch)
2023-11-06 13:18 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 35266: Fix biblio check in opac-MARCdetail (1.12 KB, patch)
2023-11-06 22:18 UTC, David Nind
Details | Diff | Splinter Review
Bug 35266: Fix biblio check in opac-MARCdetail (1.22 KB, patch)
2023-11-15 10:26 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 Marcel de Rooy 2023-11-06 13:15:06 UTC
Both opac-detail and opac-ISBDdetail check if biblio can be found and redirect if not found.
opac-MARCdetail just crashes. Since it first tries to retrieve metadata.

Easy fix.
Comment 1 Marcel de Rooy 2023-11-06 13:18:00 UTC
Created attachment 158518 [details] [review]
Bug 35266: Fix biblio check in opac-MARCdetail

We should check before retrieving metadata.

Test plan;
Try /cgi-bin/koha/opac-MARCdetail?biblionumber=X
Replace X by a not-existing biblionumber.
Verify that you get a 404 error page.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 2 David Nind 2023-11-06 22:18:07 UTC
Created attachment 158576 [details] [review]
Bug 35266: Fix biblio check in opac-MARCdetail

We should check before retrieving metadata.

Test plan;
Try /cgi-bin/koha/opac-MARCdetail?biblionumber=X
Replace X by a not-existing biblionumber.
Verify that you get a 404 error page.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: David Nind <david@davidnind.com>
Comment 3 Katrin Fischer 2023-11-10 20:06:03 UTC
I tried without the patch, but got the 404 - can you please check?

http://localhost:8080/cgi-bin/koha/opac-MARCdetail?biblionumber=11111199999
Comment 4 Marcel de Rooy 2023-11-13 07:27:31 UTC
I still see:
Can't call method "metadata" on an undefined value at /usr/share/koha/opac/opac-MARCdetail.pl line 95

You need to restart Plack. And perhaps clear the browser cache?
Comment 5 David Nind 2023-11-13 09:17:04 UTC
This is how I tested (using KTD):

1. In the OPAC, attempt to view a record that does not exist - normal view:
   . http://127.0.0.1:8080/cgi-bin/koha/opac-detail.pl?biblionumber=9999
   => redirected to the 404 page

2. In the OPAC, attempt to view a record that does not exist - ISBD view:
   . 127.0.0.1:8080/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=9999
   => redirected to the 404 page

3. In the OPAC, attempt to view a record that does not exist - MARC view:
   . 127.0.0.1:8080/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=9999
   => Get an error trace:
      Can't call method "metadata" on an undefined value at /kohadevbox/koha/opac/opac-MARCdetail.pl line 95
      ....

4. Apply the patch, restart_all, fresh browser (cache cleared).

5. Repeat step 3
   => now redirected to the 404 page, no error trace
Comment 6 Victor Grousset/tuxayo 2023-11-15 06:16:52 UTC
(In reply to Katrin Fischer from comment #3)
> I tried without the patch, but got the 404 - can you please check?
> 
> http://localhost:8080/cgi-bin/koha/opac-MARCdetail?biblionumber=11111199999

This URL ↑↑ goes to opac-MARCdetail but it should be opac-MARCdetail.pl
Comment 7 Jonathan Druart 2023-11-15 10:26:22 UTC
Created attachment 158977 [details] [review]
Bug 35266: Fix biblio check in opac-MARCdetail

We should check before retrieving metadata.

Test plan;
Try /cgi-bin/koha/opac-MARCdetail?biblionumber=X
Replace X by a not-existing biblionumber.
Verify that you get a 404 error page.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: David Nind <david@davidnind.com>

JD amended patch: Use ternary op

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 8 Tomás Cohen Arazi 2023-11-15 19:12:02 UTC
Pushed to master for 23.11.

Nice work everyone, thanks!
Comment 9 Fridolin Somers 2023-11-17 07:05:45 UTC
Pushed to 23.05.x for 23.05.06