Bug 39101

Summary: warning: "sort (...) interpreted as function" when running updatedatabase
Product: Koha Reporter: Victor Grousset/tuxayo <victor>
Component: Installation and upgrade (command-line installer)Assignee: Bugs List <koha-bugs>
Status: RESOLVED DUPLICATE QA Contact: Testopia <testopia>
Severity: normal    
Priority: P5 - low CC: dcook, jonathan.druart, tomascohen
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:
Circulation function:
Bug Depends on: 38664    
Bug Blocks:    

Description Victor Grousset/tuxayo 2025-02-11 22:04:04 UTC
sort (...) interpreted as function at /kohadevbox/koha/installer/data/mysql/updatedatabase.pl line 25950.

It starts happening after that commit:
d659526b5a Bug 38664: Tidy the whole codebase

A more minimal example can be reproduced:

```
my $var_with_long_name_1 = "2019-10-30";
my $var_with_long_name_2 = "2005-01-10";
my $var_with_long_name_3 = "2010-02-01";

# no warning
my ($max_value1) = sort ( $var_with_long_name_1, $var_with_long_name_2, $var_with_long_name_3 );
warn $max_value1;

# sort (...) interpreted as function
my ($max_value2) = sort ( $var_with_long_name_1, $var_with_long_name_2,
    $var_with_long_name_3 );

# sort (...) interpreted as function
my ($max_value3) = sort ( $var_with_long_name_1,
    $var_with_long_name_2,
    $var_with_long_name_3 );

# sort (...) interpreted as function
my ($max_value4) = sort (
    $var_with_long_name_1,
    $var_with_long_name_2,
    $var_with_long_name_3 );

```

perl -w test.pl
sort (...) interpreted as function at test.pl line 11.
sort (...) interpreted as function at test.pl line 15.
sort (...) interpreted as function at test.pl line 20.
2005-01-10 at test.pl line 8.


So somehow perl doesn't like when here the args aren't in the same line.
And the sorting is ascending so it gets the min value when it seems the intent was to get the max value!
https://gitlab.com/koha-community/Koha/-/blob/93eda45a9e6d492161096a0536a195bd257b02f3/installer/data/mysql/updatedatabase.pl?page=26#L25950
> my ($max_date) = sort ( $suggestion->{manageddate} || (), $suggestion->{accepteddate} || (),
>     $suggestion->{rejecteddate} || () );
Comment 1 Victor Grousset/tuxayo 2025-02-11 22:12:11 UTC
So I guess it can be fixed either by looking at that weird perl behavior.
Or by fixing that old DB rev so it actually gets the max_date. Assuming that's correct functionally. A fix might change the code enough to avoid the weird warning.

Just reversing the sort with { $b cmp $a } avoids the warning ^^"
my ($max_value2) = sort { $b cmp $a } ( $var_with_long_name_1, $var_with_long_name_2,
    $var_with_long_name_3 );


----


Should severity be major because it might cause doubt on whether upgrade failed or worked?
Comment 2 Jonathan Druart 2025-02-12 05:41:22 UTC
Done in bug 38664: Fix updatedatabase.pl

*** This bug has been marked as a duplicate of bug 38664 ***