Bug 22778

Summary: Suggestions with no "suggester" can cause errors
Product: Koha Reporter: Kyle M Hall (khall) <kyle>
Component: AcquisitionsAssignee: Kyle M Hall (khall) <kyle>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: normal    
Priority: P5 - low CC: 1joynelson, david.roberts, jonathan.druart, lucas, wizzyrea
Version: unspecified   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
20.05.00, 19.11.06, 19.05.11
Circulation function:
Attachments: Bug 22778: Suggestions with no "suggester" can cause errors
Bug 22778: Suggestions with no "suggester" can cause errors
Bug 22778: Suggestions with no "suggester" can cause errors
Bug 22778: Suggestions with no "suggester" can cause errors
Bug 22778: Add unit test
Bug 22778: Suggestions with no "suggester" can cause errors
Bug 22778: Add unit test

Description Kyle M Hall (khall) 2019-04-25 19:49:43 UTC
If one tries to modify a suggestion that has no suggester you will get the following error:

Can't call method "lang" on an undefined value at /usr/share/koha/lib/C4/Suggestions.pm line 506

Koha assumes that every suggestion has a borrowernumber in suggestedb.y
Comment 1 Kyle M Hall (khall) 2019-04-25 19:52:38 UTC
Created attachment 88816 [details] [review]
Bug 22778: Suggestions with no "suggester" can cause errors

If one tries to modify a suggestion that has no suggester you will get the following error:

Can't call method "lang" on an undefined value at /usr/share/koha/lib/C4/Suggestions.pm line 506

Koha assumes that every suggestion has a borrowernumber in suggestedby

Test Plan:
1) Create a suggestion with an unpopulated suggestedby
2) Attempt to modify that suggestion
3) Note the error
4) Apply this patch
5) Restart all teh things
6) Attempt to modify that suggestion
7) No error!
Comment 2 Liz Rea 2019-05-11 02:14:13 UTC
Oh you are not going to like this:

Using index info to reconstruct a base tree...
M	C4/Suggestions.pm
Falling back to patching base and 3-way merge...
Auto-merging C4/Suggestions.pm
CONFLICT (content): Merge conflict in C4/Suggestions.pm
error: Failed to merge in the changes.

Terribly sorry >.<

Liz
Comment 3 Kyle M Hall (khall) 2020-04-01 15:11:30 UTC
Created attachment 102229 [details] [review]
Bug 22778: Suggestions with no "suggester" can cause errors

If one tries to modify a suggestion that has no suggester you will get the following error:

Can't call method "lang" on an undefined value at /usr/share/koha/lib/C4/Suggestions.pm line 506

Koha assumes that every suggestion has a borrowernumber in suggestedby

Test Plan:
1) Create a suggestion with an unpopulated suggestedby
2) Attempt to modify that suggestion
3) Note the error
4) Apply this patch
5) Restart all teh things
6) Attempt to modify that suggestion
7) No error!
Comment 4 David Roberts 2020-04-05 16:16:37 UTC
I've been unable to create a suggestion without a populated suggestedby field. Even anonymous suggestions have a borrowernumber for the Anonymous patron, which I believe is correct behaviour. What is the workflow for creating a suggestion with no suggester?
Comment 5 Katrin Fischer 2020-04-05 18:47:30 UTC
Maybe try and delete the patron - I think we had a case where this caused an issue.
Comment 6 David Roberts 2020-04-05 23:07:48 UTC
Created attachment 102426 [details] [review]
Bug 22778: Suggestions with no "suggester" can cause errors

If one tries to modify a suggestion that has no suggester you will get the following error:

Can't call method "lang" on an undefined value at /usr/share/koha/lib/C4/Suggestions.pm line 506

Koha assumes that every suggestion has a borrowernumber in suggestedby

Test Plan:
1) Create a suggestion with an unpopulated suggestedby
2) Attempt to modify that suggestion
3) Note the error
4) Apply this patch
5) Restart all teh things
6) Attempt to modify that suggestion
7) No error!

Signed-off-by: David Roberts <david@koha-ptfs.co.uk>
Comment 7 David Roberts 2020-04-05 23:09:23 UTC
(In reply to Katrin Fischer from comment #5)
> Maybe try and delete the patron - I think we had a case where this caused an
> issue.

Thanks, yes that worked so I've signed it off. I can't help feeling however that it would be better if we prevented any users from being deleted if they had suggestions attached. This seems like an ingenious solution to a problem that should never have been allowed to happen in the first place! :-)
Comment 8 Katrin Fischer 2020-04-06 06:13:15 UTC
(In reply to David Roberts from comment #7)
> (In reply to Katrin Fischer from comment #5)
> > Maybe try and delete the patron - I think we had a case where this caused an
> > issue.
> 
> Thanks, yes that worked so I've signed it off. I can't help feeling however
> that it would be better if we prevented any users from being deleted if they
> had suggestions attached. This seems like an ingenious solution to a problem
> that should never have been allowed to happen in the first place! :-)

We could add a warning maybe, but I think it's not quite possible to prevent - there might be suggestions that have already been purchased/finished and the library might still want to report on them.
Comment 9 Jonathan Druart 2020-04-08 09:23:24 UTC
Can you provide tests please?

What about doing that instead:

-    if ( $suggestion->{STATUS} ) {
+    if ( $suggestion->{STATUS} && $suggestion_object->suggestedby ) {

That will let us hit the expected "return 1" at the end of the subroutine.
Comment 10 Kyle M Hall (khall) 2020-04-08 15:05:47 UTC
Created attachment 102581 [details] [review]
Bug 22778: Suggestions with no "suggester" can cause errors

If one tries to modify a suggestion that has no suggester you will get the following error:

Can't call method "lang" on an undefined value at /usr/share/koha/lib/C4/Suggestions.pm line 506

Koha assumes that every suggestion has a borrowernumber in suggestedby

Test Plan:
1) Create a suggestion with an unpopulated suggestedby
2) Attempt to modify that suggestion
3) Note the error
4) Apply this patch
5) Restart all teh things
6) Attempt to modify that suggestion
7) No error!

Signed-off-by: David Roberts <david@koha-ptfs.co.uk>
Comment 11 Kyle M Hall (khall) 2020-04-08 15:05:55 UTC
Created attachment 102582 [details] [review]
Bug 22778: Add unit test
Comment 12 Jonathan Druart 2020-04-09 10:52:48 UTC
Created attachment 102611 [details] [review]
Bug 22778: Suggestions with no "suggester" can cause errors

If one tries to modify a suggestion that has no suggester you will get the following error:

Can't call method "lang" on an undefined value at /usr/share/koha/lib/C4/Suggestions.pm line 506

Koha assumes that every suggestion has a borrowernumber in suggestedby

Test Plan:
1) Create a suggestion with an unpopulated suggestedby
2) Attempt to modify that suggestion
3) Note the error
4) Apply this patch
5) Restart all teh things
6) Attempt to modify that suggestion
7) No error!

Signed-off-by: David Roberts <david@koha-ptfs.co.uk>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 13 Jonathan Druart 2020-04-09 10:52:52 UTC
Created attachment 102612 [details] [review]
Bug 22778: Add unit test

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Amended patch: replace "suggestor" with "suggester"
Comment 14 Martin Renvoize (ashimema) 2020-04-14 07:36:41 UTC
Nice work everyone!

Pushed to master for 20.05
Comment 15 Joy Nelson 2020-05-04 20:57:37 UTC
backported to 19.11.x for 19.11.06
Comment 16 Lucas Gass (lukeg) 2020-05-13 21:09:01 UTC
backported to 19.05.x for 19.05.11