Bug 29883

Summary: Uninitialized value warning when GetAuthorisedValues gets called with no parameters
Product: Koha Reporter: Peter Vashchuk <stalkernoid>
Component: Architecture, internals, and plumbingAssignee: Peter Vashchuk <stalkernoid>
Status: CLOSED FIXED QA Contact: Jonathan Druart <jonathan.druart>
Severity: enhancement    
Priority: P5 - low CC: david, jonathan.druart, lucas, martin.renvoize, nugged, tomascohen, victor
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
22.11.00, 22.05.01
Bug Depends on:    
Bug Blocks: 25790, 30870    
Attachments: Bug 29883: avoid uninitialized value warn in GetAuthorisedValues sub
Bug 29883: avoid uninitialized value warn in GetAuthorisedValues sub
Bug 29883: avoid uninitialized value warn in GetAuthorisedValues sub
Bug 29883: Add test

Description Peter Vashchuk 2022-01-14 09:52:54 UTC

    
Comment 1 Peter Vashchuk 2022-01-14 09:58:19 UTC
Created attachment 129472 [details] [review]
Bug 29883: avoid uninitialized value warn in GetAuthorisedValues sub

GetAuthorisedValues is defined with optional parameter $category but it
is instantly interpolated without preventing "Use of uninitialized value
$category in concatenation (.) or string at .../C4/Koha.pm line 491."
warning.
As category param is optional, we can avoid throwing that warn as it is
something that can happen and is not an actual error:
C<$category> returns authorized values for just one category (optional).
Comment 2 David Nind 2022-02-05 22:14:49 UTC
Happy to test, but how can I generate the warning? Want to generate the warning, however that is done), then see if it goes away after the patch is applied.

I updated the description for the OPAC for authorised values for CCODE and viewed records in the OPAC. This didn't generate the warning.

(There is a different warning though when accessing the details page in the OPAC and staff interface: [2022/02/05 22:08:30] [WARN] Use of uninitialized value $value in concatenation (.) or string at /kohadevbox/koha/C4/XSLT.pm line 289.)
Comment 3 Andrii Nugged 2022-02-10 00:04:40 UTC
Let me help with this, I will try to find where...
I see there's dry call to:

    my $avs = C4::Koha::GetAuthorisedValues();

in svc url: /cgi-bin/koha/svc/cataloguing/framework
Aha, ... so here:

David: if you go from the usual MARC-editor (new record):

http://localhost:8080/cgi-bin/koha/cataloguing/addbiblio.pl?frameworkcode=

into the advanced editor (Settings -> Switch to the advanced editor):

so URL will be:

   /cgi-bin/koha/cataloguing/editor.pl

you will get that warning without this patch and won't get with the patch.
Comment 4 David Nind 2022-02-16 18:28:43 UTC
Thanks Andrew!

The advanced editor is currently broken in master (bug 30097), so I'll look at this when that is fixed (unless someone else beats me to it!). 

David
Comment 5 Andrii Nugged 2022-02-17 18:11:46 UTC
ok I might to search for another "reproduction example", as I know Petro got this warning just from many production logs as a "statistical frequent one" ... there is a need to go deeper into production logs (I might then...) to find what request sequence caused it.
Comment 6 David Nind 2022-05-31 04:38:53 UTC
Created attachment 135462 [details] [review]
Bug 29883: avoid uninitialized value warn in GetAuthorisedValues sub

GetAuthorisedValues is defined with optional parameter $category but it
is instantly interpolated without preventing "Use of uninitialized value
$category in concatenation (.) or string at .../C4/Koha.pm line 491."
warning.
As category param is optional, we can avoid throwing that warn as it is
something that can happen and is not an actual error:
C<$category> returns authorized values for just one category (optional).

Signed-off-by: David Nind <david@davidnind.com>
Comment 7 David Nind 2022-05-31 04:45:04 UTC
Testing notes using (koha-testing-docker):

1. Generated error ([2022/05/31 04:34:48] [WARN] Use of uninitialized value $category in concatenation (.) or string at /kohadevbox/koha/C4/Koha.pm line 491.)
by:
   . enabling the Advanced Catalogiing Editor (system preference EnableAdvancedCatalogingEditor)
   . from the cataloging module, creating a new record
   . switching between the basic editor and advanced editor
   . view the log to see the message: vi /var/log/koha/kohadev/plack-intranet-error.log

2. After patch applied and step 1 repeated, the error message was no longer added to the log.
Comment 8 Jonathan Druart 2022-05-31 09:27:04 UTC
Created attachment 135481 [details] [review]
Bug 29883: avoid uninitialized value warn in GetAuthorisedValues sub

GetAuthorisedValues is defined with optional parameter $category but it
is instantly interpolated without preventing "Use of uninitialized value
$category in concatenation (.) or string at .../C4/Koha.pm line 491."
warning.
As category param is optional, we can avoid throwing that warn as it is
something that can happen and is not an actual error:
C<$category> returns authorized values for just one category (optional).

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 9 Jonathan Druart 2022-05-31 09:27:09 UTC
Created attachment 135482 [details] [review]
Bug 29883: Add test

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 10 Tomás Cohen Arazi 2022-06-01 16:41:51 UTC
Pushed to master for 22.11.

Nice work everyone, thanks!
Comment 11 Lucas Gass 2022-06-06 15:34:56 UTC
Backported to 22.05.x for 22.05.01
Comment 12 Victor Grousset/tuxayo 2022-06-25 21:47:17 UTC
Not backported to oldoldstable (21.05.x). Feel free to ask if it's needed.