Bug 13025 - Software error: Undefined subroutine &C4::Circulation::HasOverdues called at /home/koha/kohaclone/C4/Circulation.pm line 1925
Summary: Software error: Undefined subroutine &C4::Circulation::HasOverdues called at ...
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Circulation (show other bugs)
Version: master
Hardware: All All
: P5 - low minor (vote)
Assignee: Olli-Antti Kivilahti
QA Contact: Testopia
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-10-02 19:28 UTC by Barton Chittenden
Modified: 2015-12-03 22:02 UTC (History)
10 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Bot Control: ---
When did the bot last check this:
Who signed the patch off:
Text to go in the release notes:


Attachments
Bug 13025 - Software error: Undefined subroutine &C4::Circulation::HasOverdues called at /home/koha/kohaclone/C4/Circulation.pm line 1925 (3.17 KB, patch)
2015-01-08 13:09 UTC, Olli-Antti Kivilahti
Details | Diff | Splinter Review
[SIGNED-OFF] Bug 13025 - Software error: Undefined subroutine &C4::Circulation::HasOverdues called at /home/koha/kohaclone/C4/Circulation.pm line 1925 (3.23 KB, patch)
2015-01-09 11:49 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 13025 - Software error: Undefined subroutine &C4::Circulation::HasOverdues called at /home/koha/kohaclone/C4/Circulation.pm line 1925 (3.39 KB, patch)
2015-01-09 14:50 UTC, Jonathan Druart
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Barton Chittenden 2014-10-02 19:28:13 UTC
One of our partners is seeing the following Software error intermittently on checkout:

Undefined subroutine &C4::Circulation::HasOverdues called at /home/koha/kohaclone/C4/Circulation.pm line 1925, <DATA> line 522.


Here's the offending code:

1924     # Remove any OVERDUES related debarment if the borrower has no overdues
1925     if ( $borrowernumber
1926       && $borrower->{'debarred'}
1927       && C4::Context->preference('AutoRemoveOverduesRestrictions')
1928       && !HasOverdues( $borrowernumber )
1929       && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) }
1930     ) {
1931         DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
1932     }


I'm not *entirely* sure why this is happening -- HasOverdues is defined in C4/Members.pm:


  53     push @EXPORT, qw(
  54         &Search
  55         &GetMemberDetails
  56         &GetMemberRelatives

...

 108         HasOverdues
 109     );

and C4::Members is being included in C4/Circulation.pm:

  30 use C4::Members;

... so !HasOverdues( $borrowernumber ) *shouldn't* be interpreted as a call to &C4::Circulation::HasOverdues ... nonetheless, calling


1928       && !HasOverdues( $borrowernumber )

could be re-written as
1928       && ! C4::Members::HasOverdues( $borrowernumber )

which would be un-ambiguously correct.

For the sake of consistency, the call to HasOverdues at C4/Circulation.pm line 2626 should also be changed.
Comment 1 Olli-Antti Kivilahti 2015-01-07 18:00:56 UTC
Hi!

This issue is plaguing us as well. It manifested as we barred all Borrowers with fines during the new-year. Now our check-in machine is cutting the connection all the time :) I managed to fix the issue and will share a patch ASAP.
Since Mr. Chittenden has identified this issue, I wonder why he hasn't shared a patch already?
Comment 2 Olli-Antti Kivilahti 2015-01-08 13:09:11 UTC Comment hidden (obsolete)
Comment 3 Jonathan Druart 2015-01-08 14:16:57 UTC
I am curious to know why C4::Circulation does not see HasOverdues. The subroutine is exported from C4::Member, which is used in C4::Circ.
What I missed?
Comment 4 Marcel de Rooy 2015-01-08 14:37:20 UTC
(In reply to Jonathan Druart from comment #3)
> I am curious to know why C4::Circulation does not see HasOverdues. The
> subroutine is exported from C4::Member, which is used in C4::Circ.
> What I missed?

Yeah, must be something strange in C4/SIP/.. ?
Comment 5 Olli-Antti Kivilahti 2015-01-08 16:20:50 UTC
I agree. The issue is very strange, but I have a gut feeling finding the root cause is not going to be easy.

Regardless using implicit function calls is bad practice (imho) and the Perl manual somewhere says that the Perl compiler/interpreter tries it's best to do-the-right-thing TM but implicit declarations are not always dealt with as is expected to happen.

I'll test some more whether breaking the multiline boolean soup will fix anything.
Comment 6 Olli-Antti Kivilahti 2015-01-08 16:33:11 UTC
!!!!! This is the original code !!!!!

# Remove any OVERDUES related debarment if the borrower has no overdues
    if ( $borrowernumber&& $borrower->{'debarred'}
      && C4::Context->preference('AutoRemoveOverduesRestrictions')
      && !HasOverdues( $borrowernumber )
      && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) }
    ) {
        DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
    }


!!!!! I tried with this one, but got the same error !!!!!
# Remove any OVERDUES related debarment if the borrower has no overdues
    if ( not(HasOverdues( $borrowernumber ))  ) {
        DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
    }


!!!!! If someone knows what is the root cause, let me know :) !!!!!
Comment 7 Kyle M Hall 2015-01-09 11:49:09 UTC Comment hidden (obsolete)
Comment 8 Jonathan Druart 2015-01-09 14:44:38 UTC
(In reply to Olli-Antti Kivilahti from comment #6)
> !!!!! I tried with this one, but got the same error !!!!!
> # Remove any OVERDUES related debarment if the borrower has no overdues
>     if ( not(HasOverdues( $borrowernumber ))  ) {
>         DelUniqueDebarment({ borrowernumber => $borrowernumber, type =>
> 'OVERDUES' });
>     }
> 
> 
> !!!!! If someone knows what is the root cause, let me know :) !!!!!

I don't understand the problem here. The error comes from HasOverdues, and it is still called in this code.
Comment 9 Jonathan Druart 2015-01-09 14:50:49 UTC
Created attachment 35087 [details] [review]
Bug 13025 - Software error: Undefined subroutine &C4::Circulation::HasOverdues called at /home/koha/kohaclone/C4/Circulation.pm line 1925

This error only appears when using the SIPServer, it doesn't manifest when using the SIP unit tests
or when using the staff client.

--------------------
 ------------------
  PREPARE THE TEST
 ------------------
--------------------

0a. Find a borrower.
0b. Find an Item (cardnumber 'debar123') and check-out to the borrower
0c. Find a borrower and add a manual debarrment to it, indefinetely in effect.
    This is the default behaviour.
0d. Configure and start a SIP-server which you can access with telnet.
    See http://wiki.koha-community.org/wiki/Koha_SIP2_server_setup
    In this example, the Borrower defined as the Check-out/in machine has the following credentials:
    username: herkules password: palautathan branchcode: JOE_JOE
    but you are free to use your own, it doesn't affect this test plan.
0e. access your server with telnet

-----------------------
 ---------------------
  REPLICATE THE ISSUE
 ---------------------
-----------------------
1. Paste the following SIP-command to login:
9300CNherkules|COpalautathan|CPJOE_JOE|
2. Paste the following SIP-command to check-in the Item of the debarred Borrower:
09N20140721    07501620140721    075016AP|AO|ABdebar123|AC|BIN|
3. The connection should die and in the SIP Server's error log you can find the following error:
Software error: Undefined subroutine &C4::Circulation::HasOverdues called at /home/koha/kohaclone/C4/Circulation.pm line 1925

--------------------
 ------------------
  AFTER THIS PATCH
 ------------------
--------------------

Redo steps 1-2.
3. No error is given and the connection doesn't die.

No unit tests included and never will, because setting up the test environment would be very tedious.
It is entirely possible but the scaffolding required is beyond the scope of this patch.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Note: I did not test this patch with SIP, but I did not find any
regression on checking or renewing an item.
Comment 10 Tomás Cohen Arazi 2015-01-10 19:06:52 UTC
What Perl version? I have the feeling that it should be fixed on SIP code.
Comment 11 Tomás Cohen Arazi 2015-01-21 14:15:44 UTC
Patch pushed to master.

Thanks Olli!
Comment 12 Chris Cormack 2015-02-02 08:51:36 UTC
Pushed to 3.18.x will be in 3.18.4
Comment 13 Mason James 2015-02-26 02:49:17 UTC
(In reply to Chris Cormack from comment #12)
> Pushed to 3.18.x will be in 3.18.4

Pushed to 3.16.x, will be in 3.16.8