Bug 40861 - "Odd number of elements in anonymous hash" warning in serials/acqui-search-result.pl
Summary: "Odd number of elements in anonymous hash" warning in serials/acqui-search-re...
Status: Pushed to stable
Alias: None
Product: Koha
Classification: Unclassified
Component: Acquisitions (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal
Assignee: Jonathan Druart
QA Contact: Marcel de Rooy
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-09-23 13:55 UTC by Marcel de Rooy
Modified: 2025-09-25 16:31 UTC (History)
1 user (show)

See Also:
GIT URL:
Change sponsored?: ---
Patch complexity: Trivial patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
25.11.00,25.05.04
Circulation function:


Attachments
Bug 40861: Remove warning from serials/acqui-search-result.pl (2.19 KB, patch)
2025-09-23 14:22 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 40861: Remove warning from serials/acqui-search-result.pl (2.28 KB, patch)
2025-09-23 14:25 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 Marcel de Rooy 2025-09-23 13:55:22 UTC
PLACK-INTRANET-ERROR.LOG PROD [2025/09/22 10:55:07] [WARN] Odd number of elements in anonymous hash at /usr/share/koha/serials/acqui-search-result.pl line 80.

Associated code:
        push @{$loop_basket}, {
            basketno     => $ord->{'basketno'},
            total        => $ord->{'count(*)'},
            authorisedby => $ord->{'authorisedby'},
            creationdate => output_pref( { str => $ord->{'creationdate'} } ),
            closedate    => output_pref( { str => $ord->{'closedate'} } ),
        };

Note that SearchOrders does not create a key count(*)
Comment 1 Jonathan Druart 2025-09-23 13:58:06 UTC
output_pref can generate that:
Koha/DateUtils.pm:284     return if !defined $dt;    # NULL date
Comment 2 Jonathan Druart 2025-09-23 13:59:42 UTC
(In reply to Jonathan Druart from comment #1)
> output_pref can generate that:
> Koha/DateUtils.pm:284     return if !defined $dt;    # NULL date

Hum, maybe not

278     if ($str) {
279         local $@;
280         $dt = eval { dt_from_string($str) };
281         Koha::Exceptions::WrongParameter->throw("Invalid date '$str' passed to output_pref") if $@;
282     }
283 
284     return if !defined $dt;    # NULL date
Comment 3 Marcel de Rooy 2025-09-23 14:02:46 UTC
(In reply to Jonathan Druart from comment #1)
> output_pref can generate that:
> Koha/DateUtils.pm:284     return if !defined $dt;    # NULL date

This precedes:
    if ($str) {
        local $@;
        $dt = eval { dt_from_string($str) };
        Koha::Exceptions::WrongParameter->throw("Invalid date '$str' passed to output_pref") if $@;
    }

We passed a str. Date comes from the db. So perhaps NULL or valid date. Should trigger an exception when wrong?
Comment 4 Marcel de Rooy 2025-09-23 14:03:05 UTC
(In reply to Jonathan Druart from comment #2)
> (In reply to Jonathan Druart from comment #1)
> > output_pref can generate that:
> > Koha/DateUtils.pm:284     return if !defined $dt;    # NULL date
> 
> Hum, maybe not
> 
> 278     if ($str) {
> 279         local $@;
> 280         $dt = eval { dt_from_string($str) };
> 281         Koha::Exceptions::WrongParameter->throw("Invalid date '$str'
> passed to output_pref") if $@;
> 282     }
> 283 
> 284     return if !defined $dt;    # NULL date

Yes indeed :)
Comment 5 Jonathan Druart 2025-09-23 14:22:35 UTC
Created attachment 186810 [details] [review]
Bug 40861: Remove warning from serials/acqui-search-result.pl

Odd number of elements in anonymous hash at /kohadevbox/koha/serials/acqui-search-result.pl line 84.

it's coming from closedate that is empty, and output_pref that will
reach this return:
278     if ($str) {
279         local $@;
280         $dt = eval { dt_from_string($str) };
281         Koha::Exceptions::WrongParameter->throw("Invalid date '$str' passed to output_pref") if $@;
282     }
283
284     return if !defined $dt;    # NULL date

if str is undef, we don't enter if l.278 and return l.284
which will shift the elements of the hash (because of the list context)

We force the scalar and we are good.

There was no side-effect because closedate was the last of the list.

Note that total (and the 'count(*)' key) is not used in the template.

Test plan:
Create an order for a basket of the first vendor "My vendor" and hit
http://localhost:8081/cgi-bin/koha/serials/acqui-search-result.pl?supplier=d
Without this patch you get the warning
Odd number of elements in anonymous hash at /kohadevbox/koha/serials/acqui-search-result.pl line 84.
Comment 6 Marcel de Rooy 2025-09-23 14:25:37 UTC
Created attachment 186811 [details] [review]
Bug 40861: Remove warning from serials/acqui-search-result.pl

Odd number of elements in anonymous hash at /kohadevbox/koha/serials/acqui-search-result.pl line 84.

it's coming from closedate that is empty, and output_pref that will
reach this return:
278     if ($str) {
279         local $@;
280         $dt = eval { dt_from_string($str) };
281         Koha::Exceptions::WrongParameter->throw("Invalid date '$str' passed to output_pref") if $@;
282     }
283
284     return if !defined $dt;    # NULL date

if str is undef, we don't enter if l.278 and return l.284
which will shift the elements of the hash (because of the list context)

We force the scalar and we are good.

There was no side-effect because closedate was the last of the list.

Note that total (and the 'count(*)' key) is not used in the template.

Test plan:
Create an order for a basket of the first vendor "My vendor" and hit
http://localhost:8081/cgi-bin/koha/serials/acqui-search-result.pl?supplier=d
Without this patch you get the warning
Odd number of elements in anonymous hash at /kohadevbox/koha/serials/acqui-search-result.pl line 84.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 7 Marcel de Rooy 2025-09-23 14:26:08 UTC
PQA too
Comment 8 Lucas Gass (lukeg) 2025-09-23 22:25:48 UTC
Nice work everyone!

Pushed to main for 25.11
Comment 9 Paul Derscheid 2025-09-25 16:31:35 UTC
Nice work everyone!

Pushed to 25.05.x