Bug 27745 - Use of uninitialized value in hash element error at C4/Search.pm
Summary: Use of uninitialized value in hash element error at C4/Search.pm
Status: RESOLVED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Searching (show other bugs)
Version: master
Hardware: All All
: P5 - low trivial (vote)
Assignee: Peter Vashchuk
QA Contact: Marcel de Rooy
URL:
Keywords:
Depends on:
Blocks: 25790
  Show dependency treegraph
 
Reported: 2021-02-22 10:53 UTC by Peter Vashchuk
Modified: 2021-03-23 06:27 UTC (History)
6 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Trivial patch
Text to go in the release notes:
Version(s) released in:
21.05.00,20.11.04,20.05.10


Attachments
Bug 27745: prevent warning for uninitialized value as a hash key (1.88 KB, patch)
2021-02-22 10:56 UTC, Peter Vashchuk
Details | Diff | Splinter Review
Bug 27745: prevent warning for uninitialized value as a hash key (1.86 KB, patch)
2021-03-03 09:33 UTC, Peter Vashchuk
Details | Diff | Splinter Review
Bug 27745: prevent warning for uninitialized value as a hash key (1.93 KB, patch)
2021-03-03 15:15 UTC, Didier Gautheron
Details | Diff | Splinter Review
Bug 27745: prevent warning for uninitialized value as a hash key (2.02 KB, patch)
2021-03-05 07:43 UTC, Marcel de Rooy
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
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.