Bug 37881 - Guarantor code broken
Summary: Guarantor code broken
Status: RESOLVED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Patrons (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low critical
Assignee: Baptiste Wojtkowski (bwoj)
QA Contact: Martin Renvoize (ashimema)
URL:
Keywords: regression
Depends on: 32530
Blocks:
  Show dependency treegraph
 
Reported: 2024-09-10 10:24 UTC by Jonathan Druart
Modified: 2024-11-18 16:08 UTC (History)
8 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
24.11.00
Circulation function:


Attachments
Bug 37881: Editing patron with guarantor won't crash (1.40 KB, patch)
2024-09-11 11:39 UTC, Baptiste Wojtkowski (bwoj)
Details | Diff | Splinter Review
Bug 37881: Fix the delete button for guarantor (3.77 KB, patch)
2024-09-11 11:39 UTC, Baptiste Wojtkowski (bwoj)
Details | Diff | Splinter Review
Bug 37881: Editing patron with guarantor won't crash (1.46 KB, patch)
2024-09-12 14:13 UTC, Brendan Lawlor
Details | Diff | Splinter Review
Bug 37881: Fix the delete button for guarantor (3.83 KB, patch)
2024-09-12 14:13 UTC, Brendan Lawlor
Details | Diff | Splinter Review
Bug 37881: Editing patron with guarantor won't crash (1.92 KB, patch)
2024-09-13 11:21 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 37881: Fix the delete button for guarantor (3.89 KB, patch)
2024-09-13 11:21 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 37881: (QA follow-up) Correction to TT filters used (2.63 KB, patch)
2024-09-13 11:21 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Druart 2024-09-10 10:24:26 UTC
There are a lot of issues with this feature, but here now in main it's totally broken:

1. cannot save a patron when the relationship with the guarantor is not selected, it explodes with 500 "Invalid relationship passed, '' is not defined."
=> The UI does not block the form submission when the empty option is selected (wasn't it allowed before?)

2. If I select one, save. Then edit and save (without modifying anything): re 500 "There already exists a relationship for the same guarantor (5) and guarantee (35) combination"
Comment 1 Emmi Takkinen 2024-09-10 10:52:42 UTC
Did some testing, first issue seems to come from bug 14570 and has probably existed for a while. For second issue, indeed I'm unable to edit and save guarantee with existing guarantor relationship on main. However this works in version 24.05.01, so something must have changed recently?
Comment 2 Jonathan Druart 2024-09-10 12:58:37 UTC
(In reply to Jonathan Druart from comment #0)
> 2. If I select one, save. Then edit and save (without modifying anything):
> re 500 "There already exists a relationship for the same guarantor (5) and
> guarantee (35) combination"

Caused by bug 32530.
Comment 3 Baptiste Wojtkowski (bwoj) 2024-09-10 15:11:00 UTC
Hi,
Working on it but I have a few questions.
Concerning point 1, I do not think it is related to the bug since it does not concern the same part of the code.

Concerning point 2
Since we now always submit the old relationship to the user, it appears it is detected as a duplicate and an error is thrown while storing the object. 

I'm wondering why we throw an exception here since storing an existing relationship cannot have impact on data ? Could the fix be removing the exception thrown ? Maybe I can rework this part of the code to use no try/catch.
Comment 4 Jonathan Druart 2024-09-11 06:51:39 UTC
(In reply to Baptiste Wojtkowski (bwoj) from comment #3)
> Hi,
> Working on it but I have a few questions.
> Concerning point 1, I do not think it is related to the bug since it does
> not concern the same part of the code.

Indeed, it could be moved to a separate bug report.

> Concerning point 2
> Since we now always submit the old relationship to the user, it appears it
> is detected as a duplicate and an error is thrown while storing the object. 
> 
> I'm wondering why we throw an exception here since storing an existing
> relationship cannot have impact on data ? Could the fix be removing the
> exception thrown ? Maybe I can rework this part of the code to use no
> try/catch.

You cannot remove the exception, it is at the DB level:
  UNIQUE KEY `guarantor_guarantee_idx` (`guarantor_id`,`guarantee_id`),

It ensures that we won't have a guarantor with different relationships on a given guarantee.

All this code is weird to be honest, Koha::Patron->store takes guarantors in parameters but does not update them. We are passing the existing guarantors, (even if deleted!) and the new ones.

We are removing and adding guarantors before and after the store. So if the store fails we have already removed the guarantors (you will be prompted with a "cannot save" error, but cancelling at this point will be confusing).


Anyway, it seems that the logic is flaw and the code is buggy.

What I would do is to simply test (in the controller, sub add_guarantors) if the guarantor already exists before trying to insert it.
Comment 5 Baptiste Wojtkowski (bwoj) 2024-09-11 10:01:05 UTC
I created the bug for the 1. in BZ37890 (https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=37890)
Comment 6 Baptiste Wojtkowski (bwoj) 2024-09-11 10:29:29 UTC
Note : since we fixed the add, and the add is performed after the remove without check, the checkbox "remove" is now broken
Comment 7 Baptiste Wojtkowski (bwoj) 2024-09-11 11:39:13 UTC
Created attachment 171302 [details] [review]
Bug 37881: Editing patron with guarantor won't crash

This patch fixes issue introduced by BZ32530

Test Plan (on main):
1 - Edit a patron
2 - Do not change anything and submit -> you get an error
3 - Apply both patches
4 - Repeat 1&2 -> everything works fine
5 - Try and delete the guarantor -> it will be deleted
Comment 8 Baptiste Wojtkowski (bwoj) 2024-09-11 11:39:16 UTC
Created attachment 171303 [details] [review]
Bug 37881: Fix the delete button for guarantor

This patch fixes issue introduced by BZ32530

Test Plan (on main):
1 - Edit a patron
2 - Do not change anything and submit -> you get an error
3 - Apply both patches
4 - Repeat 1&2 -> everything works fine
5 - Try and delete the guarantor -> it will be deleted
Comment 9 Brendan Lawlor 2024-09-12 13:37:08 UTC
This patch works for editing a patron with a guarantor and deleting a guarantor.

But when adding a new guarantor, if you don't select a relationship it still crashes with the error:

Invalid relationship passed, '' is not defined. at /usr/share/perl5/Exception/Class/Base.pm line 88
Comment 10 Jonathan Druart 2024-09-12 13:57:01 UTC
(In reply to Brendan Lawlor from comment #9)
> This patch works for editing a patron with a guarantor and deleting a
> guarantor.
> 
> But when adding a new guarantor, if you don't select a relationship it still
> crashes with the error:
> 
> Invalid relationship passed, '' is not defined. at
> /usr/share/perl5/Exception/Class/Base.pm line 88

Yes, it has been moved to bug 37890. It should not be considered blocker here.
Comment 11 Brendan Lawlor 2024-09-12 14:13:44 UTC
Created attachment 171399 [details] [review]
Bug 37881: Editing patron with guarantor won't crash

This patch fixes issue introduced by BZ32530

Test Plan (on main):
1 - Edit a patron
2 - Do not change anything and submit -> you get an error
3 - Apply both patches
4 - Repeat 1&2 -> everything works fine
5 - Try and delete the guarantor -> it will be deleted

Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org>
Comment 12 Brendan Lawlor 2024-09-12 14:13:46 UTC
Created attachment 171400 [details] [review]
Bug 37881: Fix the delete button for guarantor

This patch fixes issue introduced by BZ32530

Test Plan (on main):
1 - Edit a patron
2 - Do not change anything and submit -> you get an error
3 - Apply both patches
4 - Repeat 1&2 -> everything works fine
5 - Try and delete the guarantor -> it will be deleted

Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org>
Comment 13 Martin Renvoize (ashimema) 2024-09-13 11:21:00 UTC
Created attachment 171442 [details] [review]
Bug 37881: Editing patron with guarantor won't crash

This patch fixes issue introduced by BZ32530

Test Plan (on main):
1 - Edit a patron
2 - Do not change anything and submit -> you get an error
3 - Apply both patches
4 - Repeat 1&2 -> everything works fine
5 - Try and delete the guarantor -> it will be deleted

Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 14 Martin Renvoize (ashimema) 2024-09-13 11:21:03 UTC
Created attachment 171443 [details] [review]
Bug 37881: Fix the delete button for guarantor

This patch fixes issue introduced by BZ32530

Test Plan (on main):
1 - Edit a patron
2 - Do not change anything and submit -> you get an error
3 - Apply both patches
4 - Repeat 1&2 -> everything works fine
5 - Try and delete the guarantor -> it will be deleted

Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 15 Martin Renvoize (ashimema) 2024-09-13 11:21:06 UTC
Created attachment 171444 [details] [review]
Bug 37881: (QA follow-up) Correction to TT filters used

We were missing a couple of TT filters and we were using a `$raw` where it
was more appropriate to use `html`.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 16 Martin Renvoize (ashimema) 2024-09-13 11:21:57 UTC
Apologies for not catching this earlier with bug 32530.

This is all working and other issues have been put into other bugs.

Passing QA
Comment 17 Katrin Fischer 2024-09-13 11:58:44 UTC
Pushed for 24.11!

Well done everyone, thank you!
Comment 18 Lucas Gass (lukeg) 2024-11-18 16:08:02 UTC
Missing dependencies for 24.05.x