Bug 33403

Summary: Letters.t: Foreign key exception if you do not have a numberpattern with id=1
Product: Koha Reporter: Marcel de Rooy <m.de.rooy>
Component: Test SuiteAssignee: Jonathan Druart <jonathan.druart>
Status: CLOSED FIXED QA Contact: Marcel de Rooy <m.de.rooy>
Severity: normal    
Priority: P5 - low CC: jonathan.druart
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
23.05.00,22.11.06
Circulation function:
Attachments: Bug 33403: Fix Letters.t if number pattern with id=1 does not exist
Bug 33403: Fix Letters.t if number pattern with id=1 does not exist

Description Marcel de Rooy 2023-04-04 13:13:48 UTC
Letters.t

$dbh->do(q|UPDATE subscription_numberpatterns SET numberingmethod='No. {X}' WHERE id=1|);

t/db_dependent/Letters.t .. 51/85 DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception: DBD::mysql::st execute failed: Cannot add or update a child row: a foreign key constraint fails (`koha_myclone`.`subscription`, CONSTRAINT `subscription_ibfk_2` FOREIGN KEY (`numberpattern`) REFERENCES `subscription_numberpatterns` (`id`) ON DELETE SET NULL ON UPDATE CASCADE) at /usr/share/koha/Koha/Object.pm line 170

Hmm. You should have a record with id=1 in your table. This is bad.
Comment 1 Jonathan Druart 2023-05-10 10:35:35 UTC
Created attachment 150963 [details] [review]
Bug 33403: Fix Letters.t if number pattern with id=1 does not exist

Bad assumption in DB, we should create the data we need

Test plan:
> delete from subscription_numberpatterns;

prove t/db_dependent/Letters.t
Comment 2 Marcel de Rooy 2023-05-10 11:06:50 UTC
Created attachment 150965 [details] [review]
Bug 33403: Fix Letters.t if number pattern with id=1 does not exist

Bad assumption in DB, we should create the data we need

Test plan:
> delete from subscription_numberpatterns;

prove t/db_dependent/Letters.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 3 Marcel de Rooy 2023-05-10 11:07:10 UTC
SO + QA
Comment 4 Tomás Cohen Arazi (tcohen) 2023-05-10 18:28:48 UTC
Pushed to master for 23.05.

Nice work everyone, thanks!
Comment 5 Matt Blenkinsop 2023-05-15 12:42:28 UTC
Nice work everyone!

Pushed to stable for 22.11.x