Bug 26035 - AutoMemberNum fails on very large cardnumbers
Summary: AutoMemberNum fails on very large cardnumbers
Status: Signed Off
Alias: None
Product: Koha
Classification: Unclassified
Component: Patrons (show other bugs)
Version: master
Hardware: All All
: P5 - low normal (vote)
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-07-21 21:36 UTC by Andrew Fuerste-Henry
Modified: 2020-07-31 17:45 UTC (History)
4 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Who signed the patch off:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 26035: Add tests to highlight the problem (2.08 KB, patch)
2020-07-29 12:33 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 26035: AutoMemberNum should support cardnumbers up to 32 characters (1.36 KB, patch)
2020-07-29 19:16 UTC, Andrew Fuerste-Henry
Details | Diff | Splinter Review
Bug 26035: AutoMemberNum should support cardnumbers up to 32 characters (1.42 KB, patch)
2020-07-31 17:45 UTC, ByWater Sandboxes
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Fuerste-Henry 2020-07-21 21:36:29 UTC
To recreate:
- create a borrower with cardnumber 603628999632182575912
- turn on automembernum
- create a new patron, save without a cardnumber
- see that your new patron has cardnumber 0

As part of the fixup_cardnumber sub in Patron.pm, we CAST(cardnumber AS SIGNED), which tries to make the cardnumber into a 64 bit integer. Way back in bug 13178, we increased the max length of a cardnumber to 32 characters, which is longer than a 64 bit integer can handle. So the CAST spits out a -1, to which Koha adds 1, arriving at cardnumber 0.

Why do we cast it as signed in the first place? I don't understand enough about integers to see what purpose this is serving.
Comment 1 Andrew Fuerste-Henry 2020-07-21 21:38:38 UTC
Previous comment describes the behavior I'm seeing on a partner site on 19.11.
On my test site, on both master and 19.11.x, Koha simply ignores the very large cardnumber, and falls back to the next longest card. I'm not sure what makes the difference there. Either way, it's not working as desired.
Comment 2 Jonathan Druart 2020-07-29 12:33:18 UTC
Created attachment 107492 [details] [review]
Bug 26035: Add tests to highlight the problem
Comment 3 Jonathan Druart 2020-07-29 12:33:53 UTC
I've failed to provide a solution. But I am attaching the tests I wrote in case somebody else wants to give it a try.
Comment 4 Andrew Fuerste-Henry 2020-07-29 15:22:48 UTC
So if we don't cast the cardnumber as an integer, mysql doesn't know how to properly determine the highest cardnumber. It treats them as as strings and oputs 42 higher than 218250005. If we replace "CAST(cardnumber AS SIGNED" with "(cardnumber + 0)," the math forces mysql to treat it as a number, but we end up with a cardnumber in scientific notation if our existing biggest cardnumber is as big as the initial example (603628999632182575912). 
I played around with "use bigint" and "use Math::BigInt" but didn't get quite work. They both went from 603628999632182575912 to 603628999630000000001, suggesting that it's still going to scientific notation and then back again poorly.
Comment 5 Andrew Fuerste-Henry 2020-07-29 19:16:23 UTC
Created attachment 107522 [details] [review]
Bug 26035: AutoMemberNum should support cardnumbers up to 32 characters

To test:
1- create a patron with cardnumber 12345678901234567890123456789012 (or any 32 character number)
2- turn on AutoMemberNum
3- create a new patron, save without a cardnumber
4- confirm that new patron has a cardnumber one more than the number from step 1
Comment 6 ByWater Sandboxes 2020-07-31 17:45:07 UTC
Created attachment 107655 [details] [review]
Bug 26035: AutoMemberNum should support cardnumbers up to 32 characters

To test:
1- create a patron with cardnumber 12345678901234567890123456789012 (or any 32 character number)
2- turn on AutoMemberNum
3- create a new patron, save without a cardnumber
4- confirm that new patron has a cardnumber one more than the number from step 1

Signed-off-by: Donna Bachowski <donna@bywatersolutions.com>