Bug 27745

Summary: Use of uninitialized value in hash element error at C4/Search.pm
Product: Koha Reporter: Peter Vashchuk <stalkernoid>
Component: SearchingAssignee: Peter Vashchuk <stalkernoid>
Status: CLOSED FIXED QA Contact: Marcel de Rooy <m.de.rooy>
Severity: trivial    
Priority: P5 - low CC: andrewfh, didier.gautheron, fridolin.somers, m.de.rooy, nugged, victor
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
21.05.00,20.11.04,20.05.10
Bug Depends on:    
Bug Blocks: 25790    
Attachments: Bug 27745: prevent warning for uninitialized value as a hash key
Bug 27745: prevent warning for uninitialized value as a hash key
Bug 27745: prevent warning for uninitialized value as a hash key
Bug 27745: prevent warning for uninitialized value as a hash key

Description Peter Vashchuk 2021-02-22 10:53:41 UTC

    
Comment 1 Peter Vashchuk 2021-02-22 10:56:46 UTC Comment hidden (obsolete)
Comment 2 Didier Gautheron 2021-03-03 08:46:09 UTC
Hi,

Missing in test plan:
1.a) loan the item.

Moreover elsewhere there's stuff like:

$other_items->{$key}->{location} = $shelflocations->{ $item->{location} } if $item->{location};

Shouldn't it use the same here too ?
Comment 3 Peter Vashchuk 2021-03-03 09:32:58 UTC
Hey,

I don't think you need to loan the item specifically to get this error, I tested it again and I got the error even when item wasn't leaned. Unless I misunderstood what you meant, in that case please correct me.

I agree, thanks for pointing that out. It makes more sense to change it to: 
> $other_items->{$key}->{location} = $shelflocations->{ $item->{location} } if $item->{location};
Comment 4 Peter Vashchuk 2021-03-03 09:33:38 UTC
Created attachment 117554 [details] [review]
Bug 27745: prevent warning for uninitialized value as a hash key

When you edit and save items with an empty "c - Shelving location"
field, it gets stored into the database as "NULL",
which is allowed in the database, and the field is not "required",
so this seems expected.

But when the search page is rendered, it gets value by location key
($shelflocations->{ $item->{location} }) which gives undef warning.

Solved by checking if $item->{location} is perl true.

To reproduce:
    1) Edit the book or create new one with an empty shelving location.
    2) Use the search feature to have that book in the searched list.
    3) Check plack-intranet-error.log to find "Use of uninitialized
value in hash element" error.
    4) Apply the patch.
    5) Repeat the search and check the logs again to ensure that error
didn't appear again.
Comment 5 Didier Gautheron 2021-03-03 15:15:49 UTC
Created attachment 117614 [details] [review]
Bug 27745: prevent warning for uninitialized value as a hash key

When you edit and save items with an empty "c - Shelving location"
field, it gets stored into the database as "NULL",
which is allowed in the database, and the field is not "required",
so this seems expected.

But when the search page is rendered, it gets value by location key
($shelflocations->{ $item->{location} }) which gives undef warning.

Solved by checking if $item->{location} is perl true.

To reproduce:
    1) Edit the book or create new one with an empty shelving location.
    2) Use the search feature to have that book in the searched list.
    3) Check plack-intranet-error.log to find "Use of uninitialized
value in hash element" error.
    4) Apply the patch.
    5) Repeat the search and check the logs again to ensure that error
didn't appear again.

Signed-off-by: Didier Gautheron <didier.gautheron@biblibre.com>
Comment 6 Marcel de Rooy 2021-03-05 07:43:34 UTC
Created attachment 117783 [details] [review]
Bug 27745: prevent warning for uninitialized value as a hash key

When you edit and save items with an empty "c - Shelving location"
field, it gets stored into the database as "NULL",
which is allowed in the database, and the field is not "required",
so this seems expected.

But when the search page is rendered, it gets value by location key
($shelflocations->{ $item->{location} }) which gives undef warning.

Solved by checking if $item->{location} is perl true.

To reproduce:
    1) Edit the book or create new one with an empty shelving location.
    2) Use the search feature to have that book in the searched list.
    3) Check plack-intranet-error.log to find "Use of uninitialized
value in hash element" error.
    4) Apply the patch.
    5) Repeat the search and check the logs again to ensure that error
didn't appear again.

Signed-off-by: Didier Gautheron <didier.gautheron@biblibre.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 7 Jonathan Druart 2021-03-05 12:52:00 UTC
Pushed to master for 21.05, thanks to everybody involved!
Comment 8 Fridolin Somers 2021-03-12 07:57:27 UTC
Pushed to 20.11.x for 20.11.04
Comment 9 Andrew Fuerste-Henry 2021-03-14 19:54:14 UTC
Pushed to 20.05.x for 20.05.10
Comment 10 Victor Grousset/tuxayo 2021-03-23 06:27:18 UTC
Not backported to oldoldstable (19.11.x). Feel free to ask if it's needed.