Bug 40277

Summary: Warn in C4::Koha::GetAuthorisedValues()
Product: Koha Reporter: Fridolin Somers <fridolin.somers>
Component: Architecture, internals, and plumbingAssignee: Fridolin Somers <fridolin.somers>
Status: Pushed to oldstable --- QA Contact: Testopia <testopia>
Severity: minor    
Priority: P5 - low CC: david, jonathan.druart, lucas
Version: Main   
Hardware: All   
OS: All   
GIT URL: Change sponsored?: ---
Patch complexity: Trivial patch Documentation contact:
Documentation submission: Text to go in the release notes:
This fixes the cause of an unnecessary warning message[1] in the logs when searching the OPAC when not logged in. (This warning was occurring when the OpacAdvancedSearchTypes system preference was set to something other than "itemtypes", for example "loc".) [1] Warning message: [WARN] Use of uninitialized value $branch_limit in concatenation (.) or string at ...
Version(s) released in:
25.11.00,25.05.02,24.11.08
Circulation function:
Bug Depends on:    
Bug Blocks: 25790    
Attachments: Bug 40277: Remove warn in C4::Koha::GetAuthorisedValues()
Bug 40277: Remove warn in C4::Koha::GetAuthorisedValues()
Bug 40277: Remove warn in C4::Koha::GetAuthorisedValues()
Bug 40277: Add a test

Description Fridolin Somers 2025-06-30 15:00:39 UTC
When using not logged in OPAC, we see warns :
Use of uninitialized value $branch_limit in concatenation (.) or string

It comes from C4::Koha::GetAuthorisedValues() :
     my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
     my $cache_key    = "AuthorisedValues-$category-$opac-$branch_limit";

C4::Context->userenv->{"branch"} can be undef
Comment 1 Fridolin Somers 2025-06-30 15:18:58 UTC
Created attachment 183644 [details] [review]
Bug 40277: Remove warn in C4::Koha::GetAuthorisedValues()

When using not logged in OPAC, we see warns :
Use of uninitialized value $branch_limit in concatenation (.) or string

It comes from C4::Koha::GetAuthorisedValues() :
     my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
     my $cache_key    = "AuthorisedValues-$category-$opac-$branch_limit";

C4::Context->userenv->{"branch"} can be undef

Patch fixes wy using C4::Context::mybranch()

Test plan:
1.1) Without patch
1.2) Go to OPAC without logging in, open some pages
1.3) Check you have the warning in logs
2.1) Apply patch
2.2) Go to OPAC without logging in, open some pages
2.3) Check you don't have the warning in logs
Comment 2 Fridolin Somers 2025-06-30 15:19:54 UTC
Ah I can get this warn on KTD.
Looks like it is when changing language.
Comment 3 David Nind 2025-06-30 21:26:38 UTC
I couldn't replicate the issue on KTD.
Comment 4 Jonathan Druart 2025-07-04 07:39:38 UTC
(In reply to David Nind from comment #3)
> I couldn't replicate the issue on KTD.

Set  OpacAdvancedSearchTypes  to something else than "itemtypes". eg. "loc", then go to http://localhost:8080/cgi-bin/koha/opac-search.pl
Comment 5 David Nind 2025-07-04 22:24:38 UTC
Created attachment 183803 [details] [review]
Bug 40277: Remove warn in C4::Koha::GetAuthorisedValues()

When using the OPAC and you are not logged in, there are warnings
in the logs:
[WARN] Use of uninitialized value $branch_limit in concatenation (.) or string

It comes from C4::Koha::GetAuthorisedValues() :
     my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
     my $cache_key    = "AuthorisedValues-$category-$opac-$branch_limit";

C4::Context->userenv->{"branch"} can be undef

The patch fixes using C4::Context::mybranch().

Test plan:
1. Set the OpacAdvancedSearchTypes system preference to something
   other than "itemtypes", for example "loc".
2. Go to OPAC without logging in, and perform a search.
3. Check the /var/log/koha/kohadev/plack-opac-error.log and note
   the warnings in the log:
   [WARN] Use of uninitialized value $branch_limit in concatenation (.) or ...
   (Alternative, tail the logs: tail -f /var/log/koha/kohadev/*.log
4. Apply the patch.
5. Repeat step 2 and check that there are no longer any warnings.
6. Sign off.

Signed-off-by: David Nind <david@davidnind.com>
Comment 6 David Nind 2025-07-04 22:27:59 UTC
(In reply to Jonathan Druart from comment #4)
> (In reply to David Nind from comment #3)
> > I couldn't replicate the issue on KTD.
> 
> Set  OpacAdvancedSearchTypes  to something else than "itemtypes". eg. "loc",
> then go to http://localhost:8080/cgi-bin/koha/opac-search.pl

Thanks Jonathan!

I've amended the commit message to include this step
Comment 7 Jonathan Druart 2025-07-07 13:00:45 UTC
Created attachment 183838 [details] [review]
Bug 40277: Remove warn in C4::Koha::GetAuthorisedValues()

When using the OPAC and you are not logged in, there are warnings
in the logs:
[WARN] Use of uninitialized value $branch_limit in concatenation (.) or string

It comes from C4::Koha::GetAuthorisedValues() :
     my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
     my $cache_key    = "AuthorisedValues-$category-$opac-$branch_limit";

C4::Context->userenv->{"branch"} can be undef

The patch fixes using C4::Context::mybranch().

Test plan:
1. Set the OpacAdvancedSearchTypes system preference to something
   other than "itemtypes", for example "loc".
2. Go to OPAC without logging in, and perform a search.
3. Check the /var/log/koha/kohadev/plack-opac-error.log and note
   the warnings in the log:
   [WARN] Use of uninitialized value $branch_limit in concatenation (.) or ...
   (Alternative, tail the logs: tail -f /var/log/koha/kohadev/*.log
4. Apply the patch.
5. Repeat step 2 and check that there are no longer any warnings.
6. Sign off.

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

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 8 Jonathan Druart 2025-07-07 13:00:47 UTC
Created attachment 183839 [details] [review]
Bug 40277: Add a test

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 9 Fridolin Somers 2025-07-07 13:06:19 UTC
Thanks a lot for the UT Joubu ;)
Comment 10 Lucas Gass (lukeg) 2025-07-07 16:24:05 UTC
Nice work everyone!

Pushed to main for 25.11
Comment 11 Paul Derscheid 2025-07-10 20:51:10 UTC
Nice work everyone!

Pushed to 25.05.x
Comment 12 Fridolin Somers 2025-07-28 09:04:35 UTC
Pushed to 24.11.x for 24.11.08