Bug 33188 - Warning in Koha::Items->hidden_in_opac
Summary: Warning in Koha::Items->hidden_in_opac
Status: Pushed to main
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal
Assignee: Jonathan Druart
QA Contact: Tomás Cohen Arazi (tcohen)
URL:
Keywords:
Depends on:
Blocks: 25790
  Show dependency treegraph
 
Reported: 2023-03-09 21:16 UTC by Fridolin Somers
Modified: 2024-10-31 10:04 UTC (History)
3 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:
24.11.00
Circulation function:


Attachments
Bug 33188: Remove warning from Koha::Item->hidden_in_opac (1.89 KB, patch)
2024-10-29 13:42 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 33188: Remove warning from Koha::Item->hidden_in_opac (1.93 KB, patch)
2024-10-30 18:00 UTC, David Nind
Details | Diff | Splinter Review
Bug 33188: Remove warning from Koha::Item->hidden_in_opac (2.03 KB, patch)
2024-10-30 18:05 UTC, Tomás Cohen Arazi (tcohen)
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Fridolin Somers 2023-03-09 21:16:19 UTC
In Koha::Items->hidden_in_opac there is often a warning :
  Use of uninitialized value in string eq at /home/koha/src/Koha/Item.pm line 633.
This the line :
  if ( any { $self->$field eq $_ } @{ $rules->{$field} } ) {

When $self->$field is undef, the eq creates the warn.
This can happen with any nillable field like items.location not yet defined after item acquisition.
Comment 1 Fridolin Somers 2023-03-09 21:18:36 UTC
Not sure how to fix.
Do we consider undef like empty string in order to allow hiding undef ?
Comment 2 David Cook 2023-03-09 22:32:07 UTC
Shouldn't it be updated to one of the following:

1.
if ( any { $self->$field && $self->$field eq $_ } @{ $rules->{$field} } ) {

2.
if ( any { my $field = $self->$field; ($field && $field eq $_ ) ? 1 : 0; } @{ $rules->{$field} } ) {


Or am I missing something?
Comment 3 Jonathan Druart 2024-10-29 13:42:31 UTC
Created attachment 173647 [details] [review]
Bug 33188: Remove warning from Koha::Item->hidden_in_opac

"Use of uninitialized value in string eq"

Test plan:
  prove t/db_dependent/Koha/Item.t
should return green
Comment 4 David Nind 2024-10-30 18:00:45 UTC
Created attachment 173732 [details] [review]
Bug 33188: Remove warning from Koha::Item->hidden_in_opac

"Use of uninitialized value in string eq"

Test plan:
  prove t/db_dependent/Koha/Item.t
should return green

Signed-off-by: David Nind <david@davidnind.com>
Comment 5 Tomás Cohen Arazi (tcohen) 2024-10-30 18:05:40 UTC
Created attachment 173733 [details] [review]
Bug 33188: Remove warning from Koha::Item->hidden_in_opac

"Use of uninitialized value in string eq"

Test plan:
  prove t/db_dependent/Koha/Item.t
should return green

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Edit: tidied the tests (tcohen)
Comment 6 Tomás Cohen Arazi (tcohen) 2024-10-30 18:07:04 UTC
Simple fix, includes tests!

Note: please remember to tidy your patches before submitting. Please refer to the relevant wiki section for setting up your editor here: https://wiki.koha-community.org/wiki/Perltidy :-P
Comment 7 Katrin Fischer 2024-10-31 10:04:01 UTC
Pushed for 24.11!

Well done everyone, thank you!