Bug 28516

Summary: Koha/Patrons/Import.t is failing randomly
Product: Koha Reporter: Jonathan Druart <jonathan.druart>
Component: Test SuiteAssignee: Jonathan Druart <jonathan.druart>
Status: CLOSED FIXED QA Contact: Tomás Cohen Arazi <tomascohen>
Severity: normal    
Priority: P5 - low CC: fridolin.somers, tomascohen, victor
Version: master   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
21.11.00,21.05.02,20.11.09
Bug Depends on: 27857    
Bug Blocks: 25551    
Attachments: Bug 28516: Prevent failures if borrower_attribute_types.mandatory=1
Bug 28516: Prevent failures if borrower_attribute_types.mandatory=1

Description Jonathan Druart 2021-06-04 13:03:06 UTC
13:51:29 koha_1       | Missing mandatory extended attribute (type=Bg9cq3e) at /kohadevbox/koha/Koha/Patrons/Import.pm line 352, <$fh> line 2.
13:51:29 koha_1       | 
13:51:29 koha_1       |         #   Failed test at t/db_dependent/Koha/Patrons/Import.t line 1108.
13:51:29 koha_1       |         #          got: '0'
13:51:29 koha_1       |         #     expected: '1'
13:51:29 koha_1       | 
13:51:29 koha_1       |         #   Failed test at t/db_dependent/Koha/Patrons/Import.t line 1135.
13:51:29 koha_1       |         #     Structures begin differing at:
13:51:29 koha_1       |         #          $got->[0] = Does not exist
13:51:29 koha_1       |         #     $expected->[0] = HASH(0x5637834005a8)
13:51:29 koha_1       |         # Looks like you failed 2 tests of 19.
13:51:29 koha_1       | 
13:51:29 koha_1       |     #   Failed test 'update existing patron'
13:51:29 koha_1       |     #   at t/db_dependent/Koha/Patrons/Import.t line 1112.
13:51:29 koha_1       |     # Looks like you failed 1 test of 17.
13:51:29 koha_1       | 
13:51:29 koha_1       | #   Failed test 'patron_attributes'
13:51:29 koha_1       | #   at t/db_dependent/Koha/Patrons/Import.t line 1114.

Master_D11 run 315 on Docker_7
Comment 1 Jonathan Druart 2021-06-04 13:04:29 UTC
Previously reported on bug 27858:

Master_D9 run 1663

11:41:11 koha_1       | [0m[92mKoha::Exceptions::Patron::MissingMandatoryExtendedAttribute[0m  {
11:41:11 koha_1       |     Parents       [92mKoha::Exceptions::Patron[0m
11:41:11 koha_1       |     public methods (3) : [92mdescription[0m, [92mFields[0m, [92mtype[0m
11:41:11 koha_1       |     private methods (0)
11:41:11 koha_1       |     internals: {
11:41:11 koha_1       |         [35megid[0m      "[93m1000 1000[0m",
11:46:27 koha_1       |         [35meuid[0m      [94m1001[0m,
11:46:27 koha_1       |         [35mgid[0m       "[93m1000 1000[0m",
11:46:27 koha_1       |         [35mmessage[0m   "[93m[0m",
11:46:27 koha_1       |         [35mpid[0m       [94m4522[0m,
11:46:27 koha_1       |         [35mtime[0m      [94m1621935671[0m,
11:46:27 koha_1       |         [35mtrace[0m     [92mDevel::StackTrace[0m,
11:46:27 koha_1       |         [35mtype[0m      "[93mVfu0SZ[0m",
11:46:27 koha_1       |         [35muid[0m       [94m1001[0m
11:46:27 koha_1       |     }
11:46:27 koha_1       | }
11:46:27 koha_1       | Missing mandatory extended attribute (type=Vfu0SZ) at /kohadevbox/koha/Koha/Patrons/Import.pm line 420, <$fh> line 2.
11:46:27 koha_1       | 
11:46:27 koha_1       |     #   Failed test at t/db_dependent/Koha/Patrons/Import.t line 902.
11:46:27 koha_1       |     #          got: '0'
11:46:27 koha_1       |     #     expected: '1'
11:46:27 koha_1       |     # Looks like you planned 17 tests but ran 1.
11:46:27 koha_1       |     # Looks like you failed 1 test of 1 run.
11:46:27 koha_1       | 
11:46:27 koha_1       | #   Failed test 'patron_attributes'
11:46:27 koha_1       | #   at t/db_dependent/Koha/Patrons/Import.t line 1114.
11:46:27 koha_1       | Can't call method "extended_attributes" on an undefined value at t/db_dependent/Koha/Patrons/Import.t line 905, <$fh> line 2.

-----

Got it locally

t/db_dependent/Koha/Patrons.t ........................................... 28/42         # No tests run!                                                           
                                                                                                                                                                  
    #   Failed test 'No tests run for subtest "extended attributes"'                                                                                              
    #   at t/db_dependent/Koha/Patrons.t line 1770.                                                                                                               
    # Looks like you failed 1 test of 110.                                                                                                                        
t/db_dependent/Koha/Patrons.t ........................................... 33/42                                                                                   
#   Failed test 'Test Koha::Patrons::merge'                                                                                                                       
#   at t/db_dependent/Koha/Patrons.t line 1774.                                                                                                                   
Missing mandatory extended attribute (type=hGA0QWrb6)# Looks like your test exited with 2 just after 33.


-----

Master_D9_My8 586 Docker_7
Comment 2 Jonathan Druart 2021-06-04 13:39:42 UTC
Created attachment 121631 [details] [review]
Bug 28516: Prevent failures if borrower_attribute_types.mandatory=1

TestBuilder will generate an integer for the
Koha::Patron::Attribute::Type object, but if 1 is picked some tests are
failing randomly
At least t/db_dependent/Koha/Patrons.t and t/db_dependent/Koha/Patrons/Import.t
The expection "Missing mandatory extended attribute" is raised when the
patron is stored.

Test plan:
The following script should return 0 when the patch is applied:

"""
use t::lib::TestBuilder;
my $builder = t::lib::TestBuilder->new;
my $x = $builder->build_object(
    {
        class => 'Koha::Patron::Attribute::Types',
    }
);
say $x->mandatory;
"""
Comment 3 Jonathan Druart 2021-06-21 11:23:33 UTC
Koha_Master_D9/1684
Comment 4 Jonathan Druart 2021-06-21 11:49:18 UTC
Will also fix 

13:40:55 koha_1       |     #   Failed test 'No tests run for subtest "extended attributes"'
13:40:55 koha_1       |     #   at t/db_dependent/Koha/Patrons.t line 1770.
13:40:55 koha_1       |     # Looks like you failed 1 test of 110.
13:40:55 koha_1       | 
13:40:55 koha_1       | #   Failed test 'Test Koha::Patrons::merge'
13:40:55 koha_1       | #   at t/db_dependent/Koha/Patrons.t line 1774.
13:40:55 koha_1       | Missing mandatory extended attribute (type=cX9Fk5KL)# Looks like your test exited with 11 just after 33.
Comment 5 Tomás Cohen Arazi 2021-06-22 13:32:05 UTC
Created attachment 122283 [details] [review]
Bug 28516: Prevent failures if borrower_attribute_types.mandatory=1

TestBuilder will generate an integer for the
Koha::Patron::Attribute::Type object, but if 1 is picked some tests are
failing randomly
At least t/db_dependent/Koha/Patrons.t and t/db_dependent/Koha/Patrons/Import.t
The expection "Missing mandatory extended attribute" is raised when the
patron is stored.

Test plan:
The following script should return 0 when the patch is applied:

"""
use t::lib::TestBuilder;
my $builder = t::lib::TestBuilder->new;
my $x = $builder->build_object(
    {
        class => 'Koha::Patron::Attribute::Types',
    }
);
say $x->mandatory;
"""

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 6 Jonathan Druart 2021-06-23 13:06:51 UTC
Pushed to master for 21.11, thanks to everybody involved!
Comment 7 Fridolin Somers 2021-08-02 20:17:50 UTC
I see it is in 21.05.x
Comment 8 Fridolin Somers 2021-08-02 20:18:18 UTC
Pushed to 20.11.x for 20.11.09
Comment 9 Victor Grousset/tuxayo 2021-08-12 22:05:43 UTC
Missing dependencies for 20.05.x, it shouldn't be affected, no backport.