Bug 34918

Summary: Koha/Items.t crashes on missing borrower 42 or 51
Product: Koha Reporter: Marcel de Rooy <m.de.rooy>
Component: Architecture, internals, and plumbingAssignee: Marcel de Rooy <m.de.rooy>
Status: CLOSED FIXED QA Contact: Katrin Fischer <katrin.fischer>
Severity: minor    
Priority: P5 - low CC: fridolin.somers
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34932
Change sponsored?: --- Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
23.11.00,23.05.05,22.11.11
Circulation function:
Bug Depends on:    
Bug Blocks: 34933    
Attachments: Bug 34918: Fix hardcoded borrowernumber 42
Bug 34918: Fix hardcoded borrowernumber 42
Bug 34918: Fix userenv for safe_to_delete tests
Bug 34918: Fix hardcoded borrowernumber 42
Bug 34918: Fix userenv for safe_to_delete tests

Description Marcel de Rooy 2023-09-26 14:21:40 UTC
$dbh->do("INSERT INTO tmp_holdsqueue (surname,borrowernumber,itemnumber) VALUES ('Clamp',42,$itemnumber)");

This is really ugly :)
Especially if you dont have the sample patrons with borrower 42..
Comment 1 Marcel de Rooy 2023-09-26 14:31:26 UTC
Test::Builder::subtest(): DBI Exception: DBD::mysql::db do failed: Cannot add or update a child row: a foreign key constraint fails (`koha_myclone`.`tmp_holdsqueue`, CONSTRAINT `tmp_holdsqueue_ibfk_3` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE) at /usr/share/perl/5.32/Test/More.pm line 809
Comment 2 Marcel de Rooy 2023-09-26 14:41:22 UTC
Apart from a simple fix for 41, it also stumbles on a missing 51 later on for safe_to_delete.

Can't call method "can_edit_items_from" on an undefined value at /usr/share/koha/Koha/Item.pm line 299.
Comment 3 Marcel de Rooy 2023-09-26 14:42:53 UTC
Created attachment 156234 [details] [review]
Bug 34918: Fix hardcoded borrowernumber 42

Test plan:
Run t/db_dependent/Koha/Item.t
Comment 4 Marcel de Rooy 2023-09-26 14:43:26 UTC
WIP: The problem with safe_to_delete must be solved too.
Comment 5 Marcel de Rooy 2023-09-27 11:13:54 UTC
Created attachment 156281 [details] [review]
Bug 34918: Fix hardcoded borrowernumber 42

Test plan:
Run t/db_dependent/Koha/Item.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 6 Marcel de Rooy 2023-09-27 11:13:56 UTC
Created attachment 156282 [details] [review]
Bug 34918: Fix userenv for safe_to_delete tests

Instead of the fallback to 51, we pass a borrower that has
permission for editing items.

Test plan:
Do not apply patch.
Run test without a borrower 51 in db. (FAIL)
Apply patch.
Run test again. (PASS)

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 7 Marcel de Rooy 2023-09-27 11:14:25 UTC
Trivial: Self SO.
Comment 8 Katrin Fischer 2023-09-29 11:35:15 UTC
Created attachment 156382 [details] [review]
Bug 34918: Fix hardcoded borrowernumber 42

Test plan:
Run t/db_dependent/Koha/Item.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Comment 9 Katrin Fischer 2023-09-29 11:35:17 UTC
Created attachment 156383 [details] [review]
Bug 34918: Fix userenv for safe_to_delete tests

Instead of the fallback to 51, we pass a borrower that has
permission for editing items.

Test plan:
Do not apply patch.
Run test without a borrower 51 in db. (FAIL)
Apply patch.
Run test again. (PASS)

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Comment 10 Tomás Cohen Arazi (tcohen) 2023-10-03 12:55:29 UTC
Pushed to master for 23.11.

Nice work everyone, thanks!
Comment 11 Fridolin Somers 2023-10-05 19:21:33 UTC
Pushed to 23.05.x for 23.05.05
Comment 12 Jacob O'Mara 2023-10-17 13:37:55 UTC
Nice work everyone!

Pushed to oldstable for 22.11.x