Bug 34932 - A missing manager (51) failed my patron test
Summary: A missing manager (51) failed my patron test
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: Main
Hardware: All All
: P5 - low minor
Assignee: Marcel de Rooy
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks: 34933
  Show dependency treegraph
 
Reported: 2023-09-27 12:44 UTC by Marcel de Rooy
Modified: 2024-07-04 20:40 UTC (History)
4 users (show)

See Also:
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:


Attachments
Bug 34932: Patron.t - Pass borrowernumber of manager to userenv (1.10 KB, patch)
2023-09-27 12:55 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 34932: Patron.t - Pass borrowernumber of manager to userenv (1.14 KB, patch)
2023-09-28 13: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-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