Bug 34932

Summary: A missing manager (51) failed my patron test
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: Testopia <testopia>
Severity: minor    
Priority: P5 - low CC: fridolin.somers, jonathan.druart, martin.renvoize, tomascohen
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34918
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 34932: Patron.t - Pass borrowernumber of manager to userenv
Bug 34932: Patron.t - Pass borrowernumber of manager to userenv

Description Marcel de Rooy 2023-09-27 12:44:40 UTC
If we have no patron 51, and we get 51 from Mocks, we have a problem.
Easy fix
Comment 1 Marcel de Rooy 2023-09-27 12:54:53 UTC
DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception: DBD::mysql::st execute failed: Cannot add or update a child row: a foreign key constraint fails (`koha_myclone`.`accountlines`, CONSTRAINT `accountlines_ibfk_borrowers_2` FOREIGN KEY (`manager_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE) at /usr/share/koha/Koha/Object.pm line 170

This line is the culprit:
$patron->account->pay({ amount => 10, debits => [ $debit ] });

The pay routine gets the manager from userenv. When there is no borrowernumber, Mocks returns 51. And when that does not exist, boom.
Comment 2 Marcel de Rooy 2023-09-27 12:55:39 UTC
Created attachment 156287 [details] [review]
Bug 34932: Patron.t - Pass borrowernumber of manager to userenv

Test plan:
Make sure that you do not have borrowr 51.
Run t/db_dependent/Koha/Patron.t.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 3 Marcel de Rooy 2023-09-27 12:56:03 UTC
Trivial: Self SO
Comment 4 Jonathan Druart 2023-09-28 13:20:09 UTC
Hum ok, certainly enough for now. Maybe we should remove the fallback and force a patron. It will help to catch missing userenv mocks.
Comment 5 Jonathan Druart 2023-09-28 13:26:17 UTC
Created attachment 156328 [details] [review]
Bug 34932: Patron.t - Pass borrowernumber of manager to userenv

Test plan:
Make sure that you do not have borrowr 51.
Run t/db_dependent/Koha/Patron.t.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 6 Tomás Cohen Arazi 2023-10-03 13:23:57 UTC
Pushed to master for 23.11.

Nice work everyone, thanks!
Comment 7 Fridolin Somers 2023-10-05 19:36:37 UTC
Pushed to 23.05.x for 23.05.05
Comment 8 Matt Blenkinsop 2023-10-17 16:57:06 UTC
Nice work everyone!

Pushed to oldstable for 22.11.x